Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FargateService trying to update ECS service when CODE_DEPLOY used

See original GitHub issue

The FargateService class is trying to update the ECS Service when a new task definition is provided to the service when DeploymentControllerType.CODE_DEPLOY is specified. When using Blue/Green deployment strategy powered by CodeDeploy in a Fargate Service, only the desired count, deployment configuration, and health check grace period can be updated using the update-service. Otherwise a new CodeDeploy deployment should be created. So I haven’t been able to do any deploy on production environment with CDK since I use CODE_DEPLOY.

Reproduction Steps

new FargateService(

Error Log

 Unable to update task definition on services with a CODE_DEPLOY deployment controller. Use AWS CodeDeploy to trigger a new deployment. (Service: AmazonECS; Status Code: 400; Error Code: InvalidParameterException; Request ID: 83f32eb8-4ed5-4263-b944-9df4d7fa3a62)


  • **CLI Version 😗*1.30.0
  • **Framework Version:**1.30.0
  • **OS 😗*MacOS Mojave
  • **Language 😗*Java

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

konstantinjcommented, May 3, 2020

Found a workaround to be able to maintain new task definition revisions with CDK and use Code Deploy with an external CLI command.

        const taskDefinitionProps = {
            cpu: 1024,
            memoryLimitMiB: 2048,

        const taskDefinition = new FargateTaskDefinition(this, 'TaskDefinition', taskDefinitionProps)

        const containerDefinitionOptions = {
            image: ContainerImage.fromEcrRepository(Repository.fromRepositoryName(this, 'Repository', 'docker'), 'latest'),
            environment: {
                NAME: 'latest',
            logging: LogDriver.awsLogs({
                logGroup: logGroup,
                streamPrefix: 'docker',
        const container = taskDefinition.addContainer('docker', containerDefinitionOptions)

            containerPort: 80,

            name: UlimitName.NOFILE,
            softLimit: 16384,
            hardLimit: 16384,

        const service = new FargateService(this, 'Service', {
            cluster: cluster,
            healthCheckGracePeriod: Duration.seconds(60),
            minHealthyPercent: 50,
            maxHealthyPercent: 200,
            deploymentController: {
                type: DeploymentControllerType.CODE_DEPLOY,
            taskDefinition: taskDefinition,

        const taskDefinitionRev = new FargateTaskDefinition(this, 'TaskDefinitionNew', {

        const cfnTaskDefinition = taskDefinitionRev.node.defaultChild as CfnTaskDefinition
        cfnTaskDefinition.cfnOptions.updateReplacePolicy = CfnDeletionPolicy.RETAIN

        const containerRev = taskDefinitionRev.addContainer('docker', {
            environment: {
                NAME: 'docker-new',
            image: ContainerImage.fromAsset('docker'),


Explanation: Cloudformation would always try to update the current task definition which would lead to an immediate update of the ecs service. This is not possible (currently) when using DeploymentControllerType.CODE_DEPLOY. By adding a new task definition logical resource in the stack but giving it the same task family, Cloudformation will create a new task definition revision. The revision that is active in the ecs service must not be changed anymore. Unfortunately Cloudformation will remove old revisions. There the updateReplacePolicy needs to be set to retain.

For automating it the newly created task definition revision can be retrieved from the updated stack which can then be used in a cli call like:

aws ecs deploy ...
MrArnoldPalmercommented, Jun 17, 2020

Hey there, I’m consolidating the issues around ecs blue/green deployment support into If you think this is a separate issue feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating a service using the classic console
Amazon ECS has provided a new console experience for updating a service. For more information, see . You can update an existing service...
Read more >
How to update AWS Fargate service outside AWS code ...
Step 1 : We executed create stack command in order to create the service and loadbalancer. We have a workable service now. Traffic...
Read more >
update-service — AWS CLI 2.9.9 Command Reference
Modifies the parameters of a service. For services using the rolling update ( ECS ) you can update the desired count, deployment configuration, ......
Read more >
What I learned using AWS ECS Fargate Blue/Green ... - Medium
We had chosen the ECS Fargate service because our web ... changing this to use the CodeDeploy Blue/Green type if you want to...
Read more >
How to update ECS service automatically with the latest task ...
I am using aws ECS with Farget and I have workflow on GitHub that changes my ESC task-definition when there are changes in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found