Search code examples
aws-cloudformationamazon-ecsecs-taskdefinition

Avoid replacement of TaskDefinition with CloudFormation


I'm automating a PR process that need to create stacks through cloudformation. The problem is that, by definition https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html the old TaskDefinition revision is deleted to make place for the new/updated TaskDefinition. Is there any way to avoid the replacement and do only an update?


Solution

  • From the docs:

    To update a task definition, create a task definition revision. If the task definition is used in a service, you must update that service to use the updated task definition.

    This implies that task definition revisions are immutable and there is no way around creating a new revision.

    If you want to retain the old versions of your task definitions, you could try the UpdateReplacementPolicy with a value of Retain. Maybe it's able to keep the old revisions around. For more details check out the CloudFormation docs - UpdateReplacePolicy.

    That would look something like this:

    AWSTemplateFormatVersion: 2010-09-09
    Resources:
      taskdefinition:
        Type: 'AWS::ECS::TaskDefinition'
        UpdateReplacePolicy: Retain
        Properties: {} # Your usual properties here