Skip to content

Commit

Permalink
fix(stepfunctions-tasks): EMR Create Cluster does not support dynamic…
Browse files Browse the repository at this point in the history
… allocation of step concurrency level (#18972)

Currently, it is not possible to set the `stepConcurrencyLevel` property dynamically as the validation in
place will step over it and indicate that the value specified at a JsonPath is invalid.

This fix adds a check to skip validation if the property contains an unresolved token

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
shivlaks committed Feb 15, 2022
1 parent d8bc0d0 commit d19e538
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -206,7 +206,7 @@ export class EmrCreateCluster extends sfn.TaskStateBase {
this.validateReleaseLabel(this.props.releaseLabel);
}

if (this.props.stepConcurrencyLevel !== undefined) {
if (this.props.stepConcurrencyLevel !== undefined && !cdk.Token.isUnresolved(this.props.stepConcurrencyLevel)) {
if (this.props.stepConcurrencyLevel < 1 || this.props.stepConcurrencyLevel > 256) {
throw new Error(`Step concurrency level must be in range [1, 256], but got ${this.props.stepConcurrencyLevel}.`);
}
Expand Down
Expand Up @@ -202,6 +202,27 @@ describe('Cluster with StepConcurrencyLevel', () => {
});
});

test('can be set dynamically through JsonPath', async () => {
// WHEN
const task = new EmrCreateCluster(stack, 'Task', {
instances: {},
clusterRole,
name: 'Cluster',
serviceRole,
autoScalingRole,
stepConcurrencyLevel: sfn.JsonPath.numberAt('$.foo.bar'),
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
});

// THEN
expect(stack.resolve(task.toStateJson())).toMatchObject({
Parameters: {
'Name': 'Cluster',
'StepConcurrencyLevel.$': '$.foo.bar',
},
});
});

test('throws if < 1 or > 256', async () => {
expect(() => new EmrCreateCluster(stack, 'Task1', {
instances: {},
Expand Down

0 comments on commit d19e538

Please sign in to comment.