-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stepfunctions): distributed maps under branches
distributed maps under branch states (i.e., Parallel) do not apply the necessary permissions to run the state. this moves the bind functionality into state and calls it on both state and all child states. rather than relying on the single purpose that it is now (add distributed map perms) and fast returning all the way out, this instead just checks if the policy it is trying to add is in place before proceeding and uses that condition to return immediately.
- Loading branch information
Chelsea Urquhart
committed
Apr 20, 2024
1 parent
1d16304
commit 526527e
Showing
3 changed files
with
117 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/aws-cdk-lib/aws-stepfunctions/test/state-graph.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as assertions from '../../assertions'; | ||
import * as cdk from '../../core'; | ||
import * as stepfunctions from '../lib'; | ||
|
||
describe('State Graph', () => { | ||
test('bind adds execution permissions to state machine when distributed map is used within the primary graph', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
const map = createMap(stack); | ||
const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { | ||
definitionBody: stepfunctions.DefinitionBody.fromChainable(map), | ||
}); | ||
const stateMachineLogicalId = stack.getLogicalId(stateMachine.node.defaultChild as stepfunctions.CfnStateMachine); | ||
const template = assertions.Template.fromStack(stack); | ||
|
||
// THEN | ||
template.hasResource('AWS::IAM::Policy', createPolicyProps(stateMachineLogicalId)); | ||
}); | ||
|
||
test('bind adds execution permissions to state machine when distributed map is used within a child graph', () => { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
|
||
// WHEN | ||
const map = createMap(stack); | ||
const stateMachine = new stepfunctions.StateMachine(stack, 'StateMachine', { | ||
definitionBody: stepfunctions.DefinitionBody.fromChainable(new stepfunctions.Parallel(stack, 'Parallel', { | ||
resultPath: '$.result', | ||
}).branch( | ||
map, | ||
)), | ||
}); | ||
const stateMachineLogicalId = stack.getLogicalId(stateMachine.node.defaultChild as stepfunctions.CfnStateMachine); | ||
const template = assertions.Template.fromStack(stack); | ||
|
||
// THEN | ||
template.hasResource('AWS::IAM::Policy', createPolicyProps(stateMachineLogicalId)); | ||
}); | ||
}); | ||
|
||
function createMap(stack: cdk.Stack) { | ||
return new stepfunctions.DistributedMap(stack, 'Map', { | ||
maxConcurrency: 1, | ||
itemsPath: stepfunctions.JsonPath.stringAt('$.inputForMap'), | ||
itemSelector: { | ||
foo: 'foo', | ||
bar: stepfunctions.JsonPath.stringAt('$.bar'), | ||
}, | ||
}).itemProcessor(new stepfunctions.Pass(this, 'Pass State')); | ||
} | ||
|
||
function createPolicyProps(stateMachineLogicalId: string) { | ||
return { | ||
Properties: { | ||
PolicyDocument: { | ||
// ensure that self-starting permission is added which is necessary for distributed maps | ||
Statement: [ | ||
{ | ||
Action: 'states:StartExecution', | ||
Resource: { | ||
Ref: stateMachineLogicalId, | ||
}, | ||
}, | ||
{ | ||
Action: ['states:DescribeExecution', 'states:StopExecution'], | ||
Resource: { | ||
'Fn::Join': ['', [{ Ref: stateMachineLogicalId }, ':*']], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
} |