Search code examples
amazon-web-servicesaws-cloudformation

cloudformation ecs force new deployement


What is the equivalent of --force-new-deployment flag in cloudformation ? (aws ecs update-service --cluster --service --force-new-deployment)

In my cloudformation template, my docker image tag is latest. However I want to be able to force the redeployment if I replay the stack.

Thanks you


Solution

  • Think of CloudFormation as just a provisioning service or an orchestrator.

    Specifying an Image as repository-url/image:tag will definitely fetch the specified image with specific tag from your repo but only upon a stack operation. Once a stack operation is finished, any changes to service will be depending on the next stack operation.

    What you can do here is either having either

    • Cloudwatch Event based rule targeting a Lambda Function whenever there is an image upload to ECR.
    • Or in case of using some other repo than ECR, have a hook configured in a way that will invoke update-service --cluster --service --force-new-deployment ... command whenever there is a new image upload.

    Considerations:

    • This can lead your stack being in DRIFTED status.
    • Just make sure to keep your stack's Image property's value in sync with the latest one running within service, whenever you plan to update the stack.