Skip to content

(ecs): fromServiceAtrributes service ARN formatting #18137

@tobytipton

Description

@tobytipton

What is the problem?

Based on https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs-account-settings.html the ECS service ARN for new services has changed.

Old: arn:aws:ecs:region:aws_account_id:service/service-name

New: arn:aws:ecs:region:aws_account_id:service/cluster-name/service-name

The fromServiceAttributes does not take that into effect.

Reproduction Steps

This can be see when reviewing the EcsDeployAction when passing in a serviceArn with the old format it generates the codepipeline action configuration with the correct service name, when passing in the new format the service name becomes the clusterName/serviceName

Old Arn Format

const cluserName = 'cluster-name';
const serviceArn = 'arn:aws:ecs:region:aws_account_id:service/service-name';
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'EcsCluster', {
    clusterName=clusterName,
});

const service = ecs.Ec2Service.fromEc2ServiceAttributes(stack, 'EcsService', {
  serviceArn: serviceArn,
  cluster,
});
...
const action = new cpactions.EcsDeployAction({
  actionName: 'ECS',
  service,
  input: artifact,
});
pipeline.addStage({
  stageName: 'Deploy',
  actions: [action]
});

Results in the following service name and cluster in the ecs deploy action step.

Configuration: {
  ClusterName: 'cluster-name',
  ServiceName: 'service-name',
}

New Arn format

const cluserName = 'cluster-name';
const serviceArn = `arn:aws:ecs:region:aws_account_id:service/${clusterName}/service-name`;
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'EcsCluster', {
    clusterName=clusterName,
});

const service = ecs.Ec2Service.fromEc2ServiceAttributes(stack, 'EcsService', {
  serviceArn: serviceArn,
  cluster,
});
...
const action = new cpactions.EcsDeployAction({
  actionName: 'ECS',
  service,
  input: artifact,
});
pipeline.addStage({
  stageName: 'Deploy',
  actions: [action]
});

Results in the following service name and cluster in the ecs deploy action step.

Configuration: {
  ClusterName: 'cluster-name',
  ServiceName: 'cluster-name/service-name',
}

What did you expect to happen?

I would expect when passing either the old ARN format for services which existed previously or the new ARN format for the services would result in the correct serviceName in the configuration.

What actually happened?

The old format ARN generated the correct serviceName, the new ARN format generated the incorrect serviceName.

CDK CLI Version

N/A

Framework Version

No response

Node.js Version

N/A

OS

N/A

Language

Typescript

Language Version

No response

Other information

This can be tested by creating tests against EcsDeployAction so CDK version, nodejs, os, etc are N/A.

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-ecsRelated to Amazon Elastic ContainerbugThis issue is a bug.duplicateThis issue is a duplicate.in-progressThis issue is being actively worked on.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions