Skip to content

Commit a006b9a

Browse files
authored
fix(stepfunctions-tasks): emrcontainers has incorrect validation of entry point arguments (aws#22242)
Fixes aws#22061. Validation is too strict and fails for situations where entry point arguments is a `jsonPath.fromJsonPathAt()`. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/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/main/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 3ce8e47 commit a006b9a

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

packages/@aws-cdk/aws-stepfunctions-tasks/lib/emrcontainers/start-job-run.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
210210
}
211211

212212
private validateEntryPointArguments (entryPointArguments:sfn.TaskInput) {
213-
if (typeof entryPointArguments.value === 'string' && !sfn.JsonPath.isEncodedJsonPath(entryPointArguments.value)) {
214-
throw new Error(`Entry point arguments must be a string array or encoded JSON path, but received a non JSON path string');
215-
.`);
216-
}
217-
if (!this.isArrayOfStrings(entryPointArguments.value)) {
218-
throw new Error(`Entry point arguments must be a string array or encoded JSON path but received ${typeof entryPointArguments.value}.`);
213+
if (typeof entryPointArguments.value === 'string') {
214+
if (!sfn.JsonPath.isEncodedJsonPath(entryPointArguments.value)) {
215+
throw new Error('Entry point arguments must be a string array or an encoded JSON path, but received a non JSON path string');
216+
}
217+
} else if (!this.isArrayOfStrings(entryPointArguments.value)) {
218+
throw new Error(`Entry point arguments must be a string array or an encoded JSON path but received ${typeof entryPointArguments.value}.`);
219219
}
220220
}
221221

packages/@aws-cdk/aws-stepfunctions-tasks/test/emrcontainers/start-job-run.test.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,30 @@ describe('Invoke EMR Containers Start Job Run with ', () => {
170170
});
171171
});
172172

173+
test('Job Driver with Entry Point Arguments', () => {
174+
// WHEN
175+
const task = new EmrContainersStartJobRun(stack, 'EMR Containers Start Job Run', {
176+
...defaultProps,
177+
jobDriver: {
178+
sparkSubmitJobDriver: {
179+
entryPoint: sfn.TaskInput.fromText('entrypoint'),
180+
entryPointArguments: sfn.TaskInput.fromJsonPathAt('$.entrypointArguments'),
181+
},
182+
},
183+
});
184+
185+
// THEN
186+
expect(stack.resolve(task.toStateJson())).toMatchObject({
187+
Parameters: {
188+
JobDriver: {
189+
SparkSubmitJobDriver: {
190+
'EntryPoint': 'entrypoint',
191+
'EntryPointArguments.$': '$.entrypointArguments',
192+
},
193+
},
194+
},
195+
});
196+
});
173197

174198
test('Job Execution Role', () => {
175199
// WHEN
@@ -627,7 +651,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => {
627651
}).toThrow('Entry point must be between 1 and 256 characters in length. Received 0.');
628652
});
629653

630-
test('Entry Point Arguments is not an string array that is between 1 and 10280 entries in length', () => {
654+
test('Entry Point Arguments is not a string array that is between 1 and 10280 entries in length', () => {
631655
// WHEN
632656
const entryPointArgs = sfn.TaskInput.fromObject(new Array(10281).fill('x', 10281));
633657
const entryPointArgsNone = sfn.TaskInput.fromObject([]);
@@ -645,7 +669,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => {
645669
},
646670
},
647671
});
648-
}).toThrow('Entry point arguments must be a string array or encoded JSON path but received object');
672+
}).toThrow('Entry point arguments must be a string array or an encoded JSON path but received object');
649673

650674
// THEN
651675
expect(() => {
@@ -658,7 +682,7 @@ describe('Invoke EMR Containers Start Job Run with ', () => {
658682
},
659683
},
660684
});
661-
}).toThrow('Entry point arguments must be a string array or encoded JSON path, but received a non JSON path string');
685+
}).toThrow('Entry point arguments must be a string array or an encoded JSON path, but received a non JSON path string');
662686

663687
// THEN
664688
expect(() => {

0 commit comments

Comments
 (0)