From 5d6ace8c69a16fbfb7b8109bfa35fc70f6fadeab Mon Sep 17 00:00:00 2001 From: Masashi Tomooka Date: Tue, 16 Jul 2024 07:59:52 +0900 Subject: [PATCH 1/2] 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* --- .../lambda/call-aws-service-cross-region.ts | 12 +---- .../call-aws-service-cross-region.test.ts | 47 ++++++++++++++----- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/lambda/call-aws-service-cross-region.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/lambda/call-aws-service-cross-region.ts index 2622c61e6a29b..1d33349210338 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/lambda/call-aws-service-cross-region.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/lambda/call-aws-service-cross-region.ts @@ -11,7 +11,7 @@ import { CrossRegionAwsSdkSingletonFunction } from '../../../custom-resource-han */ export interface CallAwsServiceCrossRegionProps extends sfn.TaskStateBaseProps { /** - * The AWS service to call in AWS SDK for JavaScript v3 style. + * The AWS service to call in AWS SDK for JavaScript v3 format. * * @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/ * @example 's3' @@ -26,9 +26,7 @@ export interface CallAwsServiceCrossRegionProps extends sfn.TaskStateBaseProps { readonly action: string; /** - * Parameters for the API action call. - * - * Use PascalCase for the parameter names. + * Parameters for the API action call in AWS SDK for JavaScript v3 format. * * @default - no parameters */ @@ -112,12 +110,6 @@ export class CallAwsServiceCrossRegion extends sfn.TaskStateBase { if (!Token.isUnresolved(props.action) && !props.action.startsWith(props.action[0]?.toLowerCase())) { throw new Error(`action must be camelCase, got: ${props.action}`); } - if (props.parameters) { - const invalidKeys = Object.keys(props.parameters).filter((key) => !key.startsWith(key[0]?.toUpperCase())); - if (invalidKeys.length) { - throw new Error(`parameter names must be PascalCase, got: ${invalidKeys.join(', ')}`); - } - } // props.service expects a service name in the AWS SDK for JavaScript v3 format. // In some services, this format differs from the one used in IAM. diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/call-aws-service-cross-region.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/call-aws-service-cross-region.test.ts index d42050b34dd0a..458a9229444aa 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/call-aws-service-cross-region.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/call-aws-service-cross-region.test.ts @@ -162,6 +162,40 @@ test('with custom IAM action', () => { }); }); +test('parameters with camelCase', () => { + // WHEN + const task = new tasks.CallAwsServiceCrossRegion(stack, 'GetRestApi', { + service: 'api-gateway', + action: 'getRestApi', + parameters: { + restApiId: 'id', + }, + region: 'us-east-1', + iamResources: ['*'], + retryOnServiceExceptions: false, + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::GetAtt': [ + 'CrossRegionAwsSdk8a0c93f3dbef4b71ac137aaf2048ce7eF7430F4F', + 'Arn', + ], + }, + End: true, + Parameters: { + action: 'getRestApi', + region: 'us-east-1', + service: 'api-gateway', + parameters: { + restApiId: 'id', + }, + }, + }); +}); + test('throws with invalid integration pattern', () => { expect(() => new tasks.CallAwsServiceCrossRegion(stack, 'GetObject', { integrationPattern: sfn.IntegrationPattern.RUN_JOB, @@ -189,19 +223,6 @@ test('throws if action is not camelCase', () => { })).toThrow(/action must be camelCase, got: GetObject/); }); -test('throws if parameters has keys as not PascalCase', () => { - expect(() => new tasks.CallAwsServiceCrossRegion(stack, 'GetObject', { - service: 's3', - action: 'getObject', - parameters: { - bucket: 'my-bucket', - key: sfn.JsonPath.stringAt('$.key'), - }, - region: 'us-east-1', - iamResources: ['*'], - })).toThrow(/parameter names must be PascalCase, got: bucket, key/); -}); - test('can pass additional IAM statements', () => { // WHEN const task = new tasks.CallAwsServiceCrossRegion(stack, 'DetectLabels', { From 38e2ecf581b44fa2b81dbfa4e0c3573926343919 Mon Sep 17 00:00:00 2001 From: "Kenta Goto (k.goto)" <24818752+go-to-k@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:40:46 +0900 Subject: [PATCH 2/2] chore(roadmap): update a link in community contribution call-outs (#30864) ### Reason for this change I spoke with @adamjkeller the other day about a more appropriate PR link regarding the community contribution call-outs. I submit this PR on his behalf. ### Description of changes ### Description of how you validated changes ### 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* --- ROADMAP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ROADMAP.md b/ROADMAP.md index bfb07bc3c3259..1396b07320bb8 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -71,7 +71,7 @@ The CDK team is committed to supporting our existing library of AWS L2 abstracti Thank you to our community members that have contributed to the project. Below are some of the great contributions from the community! We'll continue to update this list as contributions come in, and please feel free to reach out on the cdk.dev slack workspace if you have any questions or feedback. - 🚀 [EventBridge Pipes Alpha Construct](https://github.com/aws/aws-cdk/pull/28388) - [Raphael Manke](https://github.com/RaphaelManke) -- 🚀 [CodePipeline support for Git branch and file path based triggers](https://github.com/aws/aws-cdk/issues/29124) - [Kenta Goto](https://github.com/go-to-k) +- 🚀 [CodePipeline support for pipeline type V2 with pipeline-level variables and triggers](https://github.com/aws/aws-cdk/pull/28538) - [Kenta Goto](https://github.com/go-to-k) - 🚀 [Cloudwatch Synthetics: Update to canary runtime support for NodeJS and Python](https://github.com/aws/aws-cdk/pull/29132) - [Henry Wilson](https://github.com/wilhen01) - 🚀 [EFS File System Replication](https://github.com/aws/aws-cdk/pull/29347) - [ kazuho cryer-shinozuka](https://github.com/badmintoncryer)