When deploying changes, you should usually use a CI/CD tool such as Jenkins. However, sometimes you may need to deploy manually.
Here are the steps to deploy code changes manually for an AWS ECS service.
Assumptions:
- AWS account ID: 135937123456
- AWS ECR repository name: sandbox-jsdom
- Image version tag: v2
- Region: us-west-1
1) Make and test code changes locally
Make your code changes and run local tests before building and pushing the image.
2) Authenticate Docker to Amazon ECR
aws ecr get-login-password --region us-west-1 | docker login --username AWS --password-stdin 135937123456.dkr.ecr.us-west-1.amazonaws.com
3) Build and tag the Docker image
docker build -t 135937123456.dkr.ecr.us-west-1.amazonaws.com/sandbox-jsdom:v2 .
4) Push the image to ECR
docker push 135937123456.dkr.ecr.us-west-1.amazonaws.com/sandbox-jsdom:v2
5) Create a new ECS task definition revision
In the ECS console:
- Open the current task definition.
- Choose Create new revision.
- Select Create new revision with JSON.
- Update the container image field to the new image:
"image": "135937123456.dkr.ecr.us-west-1.amazonaws.com/sandbox-jsdom:v2"
6) Update the ECS service
Update the ECS service to use the new task definition revision.
7) Verify deployment health
- Confirm that new tasks start successfully and pass health checks.
- If deployment fails, roll back by updating the service to the previous task definition revision.
- To troubleshoot failures, open the stopped task. Click stopped column and see details in the pop up. Review the stop reason and debug.