Search code examples
amazon-web-servicesgitlabgitlab-ciamazon-ecsamazon-ecr

AWS ECS: Force redeployment on new latest image in ECR


I know that there are already countless questions in this direction, but unfortunately I was not able to find the right answer yet. If a post already exists, please just share the link here.

I have several gitlab CI / CD pipelines. The first pipeline uses Terraform to build the complete infrastructure for an ECS cluster based on Fargate. The second / third pipeline creates nightly builds of the frontend and the backend and pushes the Docker Image with the tag "latest" into the ECR of the (staging) AWS account.

What I now want to achieve is that the corresponding ECS tasks are redeloyed so that the latest Docker images are used. I actually thought that there is a way to do this via CloudWatch Events or whatsoever, but I don't find a really good starting point here. A workaround would be to install the AWS CLI in the CI / CD pipeline and then do a service update with "force new deployment". But that doesn't seem very elegant to me. Is there any better way here?

Conditions:

  • The solution must be fully automated (either in AWS or in gitlab CI / CD)
  • Switching to AWS CodePipeline is out of discussion
  • Ideally as close as possible to AWS standards. I would like to avoid extensive lambda functions that perform numerous actions due to their maintainability.

Thanks a lot!


Solution

  • Ok, for everybody who is interested in an answer. I solved it that way: I execute the following AWS CLI command in the CICD pipeline

    aws ecs update-service --cluster <<cluster-name>> --service <<service-name>> --force-new-deployment --region <<region>>
    

    Not the solution I was looking for but it works.