2

I'm using github, jenkins, aws ECR, aws ECS.

I want to deploy automatically when github have new commit. When github have new commit, github sends a event webhook to jenkins, jenkins builds the images and pushes to ECR with tag 'latest'.

I wonder how can I make my ECS service restart task and redeploy images automatically when the ECR image is changed?

2

I don't think you can trigger re-deployment based on ECS image being updated. You can however do it as part of your Jenkins pipeline - after you push to ECR as a next step in the pipeline can run a script that will reload the task.

In fact in my pipelines I deploy the ECS Tasks through CloudFormation templates and the CloudFormation stack update is part of the pipeline. That way I update the ECS Task definition automatically every time I push a new image to non-prod ECR.

Hope that helps :)

0

There's a good article about enabling auto-deployment everytime an image is pushed to ECR here: https://medium.com/@YadavPrakshi/automate-zero-downtime-deployment-with-amazon-ecs-and-lambda-c4e49953273d

Check the following part out:

Automate Deployment whenever Docker Image gets uploaded on ECR

EC2 Container does not write logs directly to CloudWatch but CloudTrail records API activity for ECS. The flow of automation will be like this: Whenever a Upload occurs to ECR, CloudTrail records PutImage event and can write it to CloudWatch Logs. An Alarm can be triggered whenever a PutImage event is written in CloudWatch Logs which can further trigger a Lambda Function through SNS. Lambda Function Contains the code to Create Task Definition Revision and Update Service with latest Task Definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.