Skip to content

Commit 14be764

Browse files
authored
fix(stepfunctions): map property maxConcurrency is not token-aware (#20279)
Allows specifying `JsonPath.numberAt()` in `maxConcurrency` without synth-time errors and fixes #20152 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent abc1f57 commit 14be764

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/@aws-cdk/aws-stepfunctions/lib/states/map.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Token } from '@aws-cdk/core';
12
import { Construct } from 'constructs';
23
import { Chain } from '../chain';
34
import { FieldUtils } from '../fields';
@@ -190,7 +191,7 @@ export class Map extends State implements INextable {
190191
errors.push('Map state must have a non-empty iterator');
191192
}
192193

193-
if (this.maxConcurrency !== undefined && !isPositiveInteger(this.maxConcurrency)) {
194+
if (this.maxConcurrency !== undefined && !Token.isUnresolved(this.maxConcurrency) && !isPositiveInteger(this.maxConcurrency)) {
194195
errors.push('maxConcurrency has to be a positive integer');
195196
}
196197

packages/@aws-cdk/aws-stepfunctions/test/map.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('Map State', () => {
4343
},
4444
});
4545
}),
46+
4647
test('State Machine With Map State and ResultSelector', () => {
4748
// GIVEN
4849
const stack = new cdk.Stack();
@@ -84,6 +85,7 @@ describe('Map State', () => {
8485
},
8586
});
8687
}),
88+
8789
test('synth is successful', () => {
8890
const app = createAppWithMap((stack) => {
8991
const map = new stepfunctions.Map(stack, 'Map State', {
@@ -96,6 +98,7 @@ describe('Map State', () => {
9698

9799
app.synth();
98100
}),
101+
99102
test('fails in synthesis if iterator is missing', () => {
100103
const app = createAppWithMap((stack) => {
101104
const map = new stepfunctions.Map(stack, 'Map State', {
@@ -108,6 +111,7 @@ describe('Map State', () => {
108111

109112
expect(() => app.synth()).toThrow(/Map state must have a non-empty iterator/);
110113
}),
114+
111115
test('fails in synthesis when maxConcurrency is a float', () => {
112116
const app = createAppWithMap((stack) => {
113117
const map = new stepfunctions.Map(stack, 'Map State', {
@@ -121,6 +125,7 @@ describe('Map State', () => {
121125

122126
expect(() => app.synth()).toThrow(/maxConcurrency has to be a positive integer/);
123127
}),
128+
124129
test('fails in synthesis when maxConcurrency is a negative integer', () => {
125130
const app = createAppWithMap((stack) => {
126131
const map = new stepfunctions.Map(stack, 'Map State', {
@@ -134,6 +139,7 @@ describe('Map State', () => {
134139

135140
expect(() => app.synth()).toThrow(/maxConcurrency has to be a positive integer/);
136141
}),
142+
137143
test('fails in synthesis when maxConcurrency is too big to be an integer', () => {
138144
const app = createAppWithMap((stack) => {
139145
const map = new stepfunctions.Map(stack, 'Map State', {
@@ -147,22 +153,42 @@ describe('Map State', () => {
147153

148154
expect(() => app.synth()).toThrow(/maxConcurrency has to be a positive integer/);
149155
}),
156+
157+
test('does not fail synthesis when maxConcurrency is a jsonPath', () => {
158+
const app = createAppWithMap((stack) => {
159+
const map = new stepfunctions.Map(stack, 'Map State', {
160+
maxConcurrency: stepfunctions.JsonPath.numberAt('$.maxConcurrency'),
161+
itemsPath: stepfunctions.JsonPath.stringAt('$.inputForMap'),
162+
});
163+
map.iterator(new stepfunctions.Pass(stack, 'Pass State'));
164+
165+
return map;
166+
});
167+
168+
expect(() => app.synth()).not.toThrow();
169+
});
170+
150171
test('isPositiveInteger is false with negative number', () => {
151172
expect(stepfunctions.isPositiveInteger(-1)).toEqual(false);
152173
}),
174+
153175
test('isPositiveInteger is false with decimal number', () => {
154176
expect(stepfunctions.isPositiveInteger(1.2)).toEqual(false);
155177
}),
178+
156179
test('isPositiveInteger is false with a value greater than safe integer', () => {
157180
const valueToTest = Number.MAX_SAFE_INTEGER + 1;
158181
expect(stepfunctions.isPositiveInteger(valueToTest)).toEqual(false);
159182
}),
183+
160184
test('isPositiveInteger is true with 0', () => {
161185
expect(stepfunctions.isPositiveInteger(0)).toEqual(true);
162186
}),
187+
163188
test('isPositiveInteger is true with 10', () => {
164189
expect(stepfunctions.isPositiveInteger(10)).toEqual(true);
165190
}),
191+
166192
test('isPositiveInteger is true with max integer value', () => {
167193
expect(stepfunctions.isPositiveInteger(Number.MAX_SAFE_INTEGER)).toEqual(true);
168194
});

0 commit comments

Comments
 (0)