From 4356a5cff2e5f75c62e91a8f4d8ab9684137c017 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy <36202692+kaizen3031593@users.noreply.github.com> Date: Fri, 18 Feb 2022 04:44:09 -0500 Subject: [PATCH] fix(stepfunctions): imported State Machine sill has region and account from its Stack, instead of its ARN (#19026) Fixes #17982. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-stepfunctions/lib/state-machine.ts | 4 ++- .../test/state-machine.test.ts | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index 4143e4bba6601..7fe4423b8a310 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -142,7 +142,9 @@ abstract class StateMachineBase extends Resource implements IStateMachine { public readonly stateMachineArn = stateMachineArn; public readonly grantPrincipal = new iam.UnknownPrincipal({ resource: this }); } - return new Import(scope, id); + return new Import(scope, id, { + environmentFromArn: stateMachineArn, + }); } public abstract readonly stateMachineArn: string; diff --git a/packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts b/packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts index f60c0b756e66a..f99cc479c9975 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts @@ -277,4 +277,35 @@ describe('State Machine', () => { ], }); }); + + describe('StateMachine.fromStateMachineArn()', () => { + let stack: cdk.Stack; + + beforeEach(() => { + const app = new cdk.App(); + stack = new cdk.Stack(app, 'Base', { + env: { account: '111111111111', region: 'stack-region' }, + }); + }); + + describe('for a state machine in a different account and region', () => { + let mach: stepfunctions.IStateMachine; + + beforeEach(() => { + mach = stepfunctions.StateMachine.fromStateMachineArn( + stack, + 'iMach', + 'arn:aws:states:machine-region:222222222222:stateMachine:machine-name', + ); + }); + + test("the state machine's region is taken from the ARN", () => { + expect(mach.env.region).toBe('machine-region'); + }); + + test("the state machine's account is taken from the ARN", () => { + expect(mach.env.account).toBe('222222222222'); + }); + }); + }); });