Skip to content

CloudFormation Task definition is not updated during deployment #728

Closed
@rantoniuk

Description

@rantoniuk

Let me start by saying, that I'm not sure whether this report should go in this repository, CDK (for EcsService to provide a preserveTaskDefinitionRevision flag) or via AWS Support to CloudFormation team - or maybe I'm missing something.

I have a perfectly working setup that is using exactly as described in the README:


    - name: Fill in the new image ID in the Amazon ECS task definition
      id: task-def
      uses: aws-actions/amazon-ecs-render-task-definition@v1
      with:
        task-definition: task-definition.json
        container-name: my-container
        image: ${{ steps.build-image.outputs.image }}

    - name: Deploy Amazon ECS task definition
      uses: aws-actions/amazon-ecs-deploy-task-definition@v2
      with:
        task-definition: ${{ steps.task-def.outputs.task-definition }}
        service: my-service
        cluster: my-cluster

and an ECS service defined for simplicity like this:

    const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef', {
      family: 'task-def',
      taskRole: taskRole,
      networkMode: ecs.NetworkMode.AWS_VPC,
    });

    const realtimeWsService = new ecs.Ec2Service(this, 'EcsService', {
      serviceName: 'Service',
      cluster: props.cluster,
      taskDefinition,
    });

Now imagine the following scenario - which is day to day work I believe, so I'm sure someone must have already had that problem, though I couldn't find it.

  1. Deploy the CDK that creates the ECS service. This will in turn create the task-def:1 revision. Assuming all is fine with the service configuration, the service goes into steady state and CDK finishes with OK status - all good.
  2. Now, start updating that service with this action, where the action will be updating the tag of the container image. Every run of GHA amazon-ecs-deploy-task-definition action, will create a new task-def
    revision, with the updated container image.

The service deployed, let's say with task-def:10, action finished, all good, right.

Now we get to the problem, Imagine that you need to change something in the Ec2Service definition, so the CDK - standard case, you need to increase the allocated memory or CPU.

If only the CPU allocation is changed and you run cdk diff, it will only show, as expected, that the service will be updated by only updating the CPU property.

However, when you actually deploy this, you'll see, that the service is restarted again with task-def:1 revision, instead of the last revision it was running with.

This is confirmed, if I go to CloudFormation console, look up the Stack and in there I can see in the stack resources, it is "attached" to the task-def:1 revision, instead of :10.

What am I missing? How to de-couple those two things, so that an unrelated CDK change doesn't revert the task-definition that is used by the service?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions