Skip to content

Commit 23329b4

Browse files
authored
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*
1 parent a416a2d commit 23329b4

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
142142
public readonly stateMachineArn = stateMachineArn;
143143
public readonly grantPrincipal = new iam.UnknownPrincipal({ resource: this });
144144
}
145-
return new Import(scope, id);
145+
return new Import(scope, id, {
146+
environmentFromArn: stateMachineArn,
147+
});
146148
}
147149

148150
public abstract readonly stateMachineArn: string;

packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,35 @@ describe('State Machine', () => {
277277
],
278278
});
279279
});
280+
281+
describe('StateMachine.fromStateMachineArn()', () => {
282+
let stack: cdk.Stack;
283+
284+
beforeEach(() => {
285+
const app = new cdk.App();
286+
stack = new cdk.Stack(app, 'Base', {
287+
env: { account: '111111111111', region: 'stack-region' },
288+
});
289+
});
290+
291+
describe('for a state machine in a different account and region', () => {
292+
let mach: stepfunctions.IStateMachine;
293+
294+
beforeEach(() => {
295+
mach = stepfunctions.StateMachine.fromStateMachineArn(
296+
stack,
297+
'iMach',
298+
'arn:aws:states:machine-region:222222222222:stateMachine:machine-name',
299+
);
300+
});
301+
302+
test("the state machine's region is taken from the ARN", () => {
303+
expect(mach.env.region).toBe('machine-region');
304+
});
305+
306+
test("the state machine's account is taken from the ARN", () => {
307+
expect(mach.env.account).toBe('222222222222');
308+
});
309+
});
310+
});
280311
});

0 commit comments

Comments
 (0)