Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stepfunctions): support cross-account task invocations #23012

Merged
merged 15 commits into from
Dec 6, 2022
Merged
65 changes: 65 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 @@ -315,6 +315,71 @@ describe('State Machine', () => {
});
});

test('Instantiate a State Machine with a task assuming a literal roleArn from same account', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const role = iam.Role.fromRoleName(stack, 'Role', 'example-role');
corymhall marked this conversation as resolved.
Show resolved Hide resolved
new sfn.StateMachine(stack, 'MyStateMachine', {
definition: new FakeTask(stack, 'fakeTask', { credentials: { role: sfn.TaskRole.fromRole(role) } }),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', {
DefinitionString: {
'Fn::Join': [
'',
[
'{"StartAt":"fakeTask","States":{"fakeTask":{"End":true,"Type":"Task","Credentials":{"RoleArn":"arn:',
{
Ref: 'AWS::Partition',
},
':iam::',
{
Ref: 'AWS::AccountId',
},
':role/example-role"},"Resource":"my-resource","Parameters":{"MyParameter":"myParameter"}}}}',
],
],
},
});

Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Effect: 'Allow',
Action: 'sts:AssumeRole',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::',
{
Ref: 'AWS::AccountId',
},
':role/example-role',
],
],
},
},
],
Version: '2012-10-17',
},
PolicyName: 'MyStateMachineRoleDefaultPolicyE468EB18',
Roles: [
{
Ref: 'MyStateMachineRoleD59FFEBC',
},
],
});
});

test('Instantiate a State Machine with a task assuming a JSONPath roleArn', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down