Skip to content

Commit 5d6ace8

Browse files
authored
fix(stepfunctions-tasks): allow camelCase for parameters of CallAwsServiceCrossRegion (#30795)
### Issue # (if applicable) closes #30799 ### Reason for this change I found some AWS services uses camelCase for API parameters, such as [api-gateway](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/api-gateway/command/GetRestApiCommand/) or [bedrock-runtime](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/InvokeModelCommand/). However, currently `CallAwsServiceCrossRegion` allows only PascalCase for parameters, and it throws an error if parameters are not in PascalCase. ### Description of changes Because we do not precisely know which service uses camelCase, this PR just removes the validation logic to allow both camelCase and PascalCase for parameters. This will also reduce maintanance cost in the future. ### Description of how you validated changes Added a unit test. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 31b9e03 commit 5d6ace8

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/lambda/call-aws-service-cross-region.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CrossRegionAwsSdkSingletonFunction } from '../../../custom-resource-han
1111
*/
1212
export interface CallAwsServiceCrossRegionProps extends sfn.TaskStateBaseProps {
1313
/**
14-
* The AWS service to call in AWS SDK for JavaScript v3 style.
14+
* The AWS service to call in AWS SDK for JavaScript v3 format.
1515
*
1616
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/
1717
* @example 's3'
@@ -26,9 +26,7 @@ export interface CallAwsServiceCrossRegionProps extends sfn.TaskStateBaseProps {
2626
readonly action: string;
2727

2828
/**
29-
* Parameters for the API action call.
30-
*
31-
* Use PascalCase for the parameter names.
29+
* Parameters for the API action call in AWS SDK for JavaScript v3 format.
3230
*
3331
* @default - no parameters
3432
*/
@@ -112,12 +110,6 @@ export class CallAwsServiceCrossRegion extends sfn.TaskStateBase {
112110
if (!Token.isUnresolved(props.action) && !props.action.startsWith(props.action[0]?.toLowerCase())) {
113111
throw new Error(`action must be camelCase, got: ${props.action}`);
114112
}
115-
if (props.parameters) {
116-
const invalidKeys = Object.keys(props.parameters).filter((key) => !key.startsWith(key[0]?.toUpperCase()));
117-
if (invalidKeys.length) {
118-
throw new Error(`parameter names must be PascalCase, got: ${invalidKeys.join(', ')}`);
119-
}
120-
}
121113

122114
// props.service expects a service name in the AWS SDK for JavaScript v3 format.
123115
// In some services, this format differs from the one used in IAM.

packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/call-aws-service-cross-region.test.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,40 @@ test('with custom IAM action', () => {
162162
});
163163
});
164164

165+
test('parameters with camelCase', () => {
166+
// WHEN
167+
const task = new tasks.CallAwsServiceCrossRegion(stack, 'GetRestApi', {
168+
service: 'api-gateway',
169+
action: 'getRestApi',
170+
parameters: {
171+
restApiId: 'id',
172+
},
173+
region: 'us-east-1',
174+
iamResources: ['*'],
175+
retryOnServiceExceptions: false,
176+
});
177+
178+
// THEN
179+
expect(stack.resolve(task.toStateJson())).toEqual({
180+
Type: 'Task',
181+
Resource: {
182+
'Fn::GetAtt': [
183+
'CrossRegionAwsSdk8a0c93f3dbef4b71ac137aaf2048ce7eF7430F4F',
184+
'Arn',
185+
],
186+
},
187+
End: true,
188+
Parameters: {
189+
action: 'getRestApi',
190+
region: 'us-east-1',
191+
service: 'api-gateway',
192+
parameters: {
193+
restApiId: 'id',
194+
},
195+
},
196+
});
197+
});
198+
165199
test('throws with invalid integration pattern', () => {
166200
expect(() => new tasks.CallAwsServiceCrossRegion(stack, 'GetObject', {
167201
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
@@ -189,19 +223,6 @@ test('throws if action is not camelCase', () => {
189223
})).toThrow(/action must be camelCase, got: GetObject/);
190224
});
191225

192-
test('throws if parameters has keys as not PascalCase', () => {
193-
expect(() => new tasks.CallAwsServiceCrossRegion(stack, 'GetObject', {
194-
service: 's3',
195-
action: 'getObject',
196-
parameters: {
197-
bucket: 'my-bucket',
198-
key: sfn.JsonPath.stringAt('$.key'),
199-
},
200-
region: 'us-east-1',
201-
iamResources: ['*'],
202-
})).toThrow(/parameter names must be PascalCase, got: bucket, key/);
203-
});
204-
205226
test('can pass additional IAM statements', () => {
206227
// WHEN
207228
const task = new tasks.CallAwsServiceCrossRegion(stack, 'DetectLabels', {

0 commit comments

Comments
 (0)