Skip to content

Commit

Permalink
fix(stepfunctions-tasks): emrcontainers has incorrect validation of e…
Browse files Browse the repository at this point in the history
…ntry 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*
  • Loading branch information
kaizencc authored and madeline-k committed Oct 10, 2022
1 parent fce4e36 commit 41902ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ export class EmrContainersStartJobRun extends sfn.TaskStateBase implements iam.I
}

private validateEntryPointArguments (entryPointArguments:sfn.TaskInput) {
if (typeof entryPointArguments.value === 'string' && !sfn.JsonPath.isEncodedJsonPath(entryPointArguments.value)) {
throw new Error(`Entry point arguments must be a string array or encoded JSON path, but received a non JSON path string');
.`);
}
if (!this.isArrayOfStrings(entryPointArguments.value)) {
throw new Error(`Entry point arguments must be a string array or encoded JSON path but received ${typeof entryPointArguments.value}.`);
if (typeof entryPointArguments.value === 'string') {
if (!sfn.JsonPath.isEncodedJsonPath(entryPointArguments.value)) {
throw new Error('Entry point arguments must be a string array or an encoded JSON path, but received a non JSON path string');
}
} else if (!this.isArrayOfStrings(entryPointArguments.value)) {
throw new Error(`Entry point arguments must be a string array or an encoded JSON path but received ${typeof entryPointArguments.value}.`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,30 @@ describe('Invoke EMR Containers Start Job Run with ', () => {
});
});

test('Job Driver with Entry Point Arguments', () => {
// WHEN
const task = new EmrContainersStartJobRun(stack, 'EMR Containers Start Job Run', {
...defaultProps,
jobDriver: {
sparkSubmitJobDriver: {
entryPoint: sfn.TaskInput.fromText('entrypoint'),
entryPointArguments: sfn.TaskInput.fromJsonPathAt('$.entrypointArguments'),
},
},
});

// THEN
expect(stack.resolve(task.toStateJson())).toMatchObject({
Parameters: {
JobDriver: {
SparkSubmitJobDriver: {
'EntryPoint': 'entrypoint',
'EntryPointArguments.$': '$.entrypointArguments',
},
},
},
});
});

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

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

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

// THEN
expect(() => {
Expand Down

0 comments on commit 41902ec

Please sign in to comment.