Using custom-named ECS / Fargate services: CloudFormation cannot update a stack when a custom-named resource requires replacing
See original GitHub issue❓ General Issue
Hi! I think we need some advice how the AWS CDK is meant to be used when generating Fargate services. Lately, after CDK updates we have been seen a lot of following errors:
CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename cluster-name\app-name and update the stack again.
--
| Physical ID:arn:aws:ecs:eu-central-1:account-id:service/cluster-name/app-name
So far, we have manually named all of our services with simplified names. For example, the mentioned app-name
.
If we use CDK generated names we see env-name-app-nameService70147683-W8VL0MQANBBH
.
new ecs.FargateService(stack, `${prefix}-${service.name}`, {
cluster,
taskDefinition,
// uncomment to fix the name
// serviceName: service.name,
desiredCount: service.desiredCount,
enableECSManagedTags: true,
propagateTags: ecs.PropagatedTagSource.SERVICE,
})
The problem comes from our deployment pipeline which uses fixed names for services since the service name is the only proper identifier provided by AWS in this case:
# Repeat for each service and environment
- Name: UpdateDev
Actions:
- Name: DeployImage
InputArtifacts:
- Name: BuildOutput
ActionTypeId: {Category: Deploy, Owner: AWS, Version: 1, Provider: ECS}
RoleArn: !Sub arn:aws:iam::${AccountNumber}:role/deploy-role
Configuration:
ClusterName: !Sub cluster-name
ServiceName: !Ref ServiceName
FileName: imagedefinitions.json
It seems difficult to me to find a workaround for this issue since the service names for CodePipeline deployment are not known (?) before the stacks have been initialized or deployed. We have one account for deployment tools and separate accounts for testing and production environments.
The Question
What would be the “official” way to proceed without fixed names and still be able to use the CDK generated service names in deployment pipeline which is deployed in different account before any other stacks are deployed?
Environment
- CDK CLI Version: 1.10.0
- Module Version: 1.10.0
- OS: MacOS
- Language: TypeScript
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10 (9 by maintainers)
Top GitHub Comments
@markusl, this is because CloudFormation attempts to bring up the new version of your ECS/Fargate service prior to deleting the old service (this only happens on replacement). If the new service creation fails, your old service will be used to rollback.
Since you’re using a custom named resource, it is unable to create the new service with the same resource names (due to collisions). Would it make sense to have a version/revision/unique identifier appended to the end of your resource name?
Let’s close the issue if there is nothing CDK team can do to help the situation.