Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(stepfunctions-tasks): validate cases of action and parameters in CallAwsService #27635

Merged
merged 11 commits into from
Oct 24, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export class CallAwsService extends sfn.TaskStateBase {
if (this.props.integrationPattern === sfn.IntegrationPattern.RUN_JOB) {
throw new Error('The RUN_JOB integration pattern is not supported for CallAwsService');
}
if (!Token.isUnresolved(this.props.action) && !this.props.action.startsWith(this.props.action[0]?.toLowerCase())) {
throw new Error(`action must be camelCase, got: ${this.props.action}`);
}
if (this.props.parameters) {
const invalidKeys = Object.keys(this.props.parameters).filter(key => !key.startsWith(key[0]?.toUpperCase()));
if (invalidKeys.length) {
throw new Error(`parameter names must be PascalCase, got: ${invalidKeys.join(', ')}`);
}
}

const iamServiceMap: Record<string, string> = {
sfn: 'states',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ test('throws with invalid integration pattern', () => {
})).toThrow(/The RUN_JOB integration pattern is not supported for CallAwsService/);
});

test('throws if action is not camelCase', () => {
expect(() => new tasks.CallAwsService(stack, 'GetObject', {
service: 's3',
action: 'GetObject',
parameters: {
Bucket: 'my-bucket',
Key: sfn.JsonPath.stringAt('$.key'),
},
iamResources: ['*'],
})).toThrow(/action must be camelCase, got: GetObject/);
});

test('throws if parameters has keys as not PascalCase', () => {
expect(() => new tasks.CallAwsService(stack, 'GetObject', {
service: 's3',
action: 'getObject',
parameters: {
bucket: 'my-bucket',
key: sfn.JsonPath.stringAt('$.key'),
},
iamResources: ['*'],
})).toThrow(/parameter names must be PascalCase, got: bucket, key/);
});

test('can pass additional IAM statements', () => {
// WHEN
const task = new tasks.CallAwsService(stack, 'DetectLabels', {
Expand Down