Skip to content

stepfunctions-tasks: CallAwsServiceCrossRegion uses wrong casing for ECS #30799

@ADringer

Description

@ADringer

Describe the bug

Hi, I'm using the new task CallAwsServiceCrossRegion from #30061 to update an ECS service in a different region. In the task I have to pass in parameters as PascalCase but the actual call fails in the client ecs saying the service identifier has not been provided as it's expecting camelCase.

Expected Behavior

The parameters passed from the task successfully invoke the aws service. Maybe mapping the casing accordingly.

Current Behavior

The parameters are entered into the task as PascalCase:

"parameters": {
                "Cluster.$": "$.cluster",
                "Service.$": "$.service",
                "ForceNewDeployment": true
}

And this fails with the error InvalidParameterException: Service Identifier cannot be empty.

Reproduction Steps

Create a task that calls ECS e.g:

new tasks.CallAwsServiceCrossRegion(this, "ecs-update-service", {
          service: 'ecs',
          action: 'updateService',
          iamResources: ['*'],
          region: 'us-east-2',
          parameters: {
            "Cluster.$": "myCluster",
            "Service.$": "myService",
            "ForceNewDeployment": true
          },
        })

Possible Solution

Looking at the code, if ecs cdk expects all camelCase parameters, we could update this that's causing the issue:

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(', ')}`);
      }
    }

to be something like

const camelCaseServices: String[] = ['ecs'];

if (props.parameters) {
      const invalidKeys = Object.keys(props.parameters).filter((key) => !key.startsWith(key[0]?.toUpperCase()));
      if (invalidKeys.length && !camelCaseServices.include(props.service)) {
        throw new Error(`parameter names must be PascalCase, got: ${invalidKeys.join(', ')}`);
      }
    }

So this ignores the check for the ecs service, and can add other services that require camelCase

Additional Information/Context

No response

CDK CLI Version

2.147.3

Framework Version

No response

Node.js Version

20

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions