Skip to content

Commit

Permalink
fix(stepfunctions): imported State Machine sill has region and accoun…
Browse files Browse the repository at this point in the history
…t from its Stack, instead of its ARN (aws#19026)

Fixes aws#17982.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored and TikiTDO committed Feb 21, 2022
1 parent 72e1a55 commit 4356a5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});

0 comments on commit 4356a5c

Please sign in to comment.