ECS Service Rolling Deployment and Troubleshooting
Perform zero-downtime rolling deployments of ECS Fargate services, monitor task health, and troubleshoot failed deployments with circuit breaker rollbacks.
Prerequisites
- -AWS CLI v2 installed and configured
- -Existing ECS cluster and service
- -Container image pushed to ECR
Steps
Register a new task definition revision
Create a new task definition revision with the updated container image tag to prepare for deployment.
Only update the image tag, not the entire task definition. This preserves CPU, memory, environment variables, and other settings.
Remove taskDefinitionArn, revision, status, registeredAt, registeredBy, and requiresAttributes from the JSON before re-registering, or the API will reject the request.
Update the service to trigger deployment
Update the ECS service to use the new task definition revision, triggering a rolling deployment.
The --force-new-deployment flag ensures tasks are replaced even if the task definition revision has not changed, useful for pulling the latest image with a mutable tag.
Monitor the deployment progress
Watch the service deployments to track the rollout of new tasks and draining of old tasks.
Check task health and stopped reasons
List recently stopped tasks and inspect their stop reasons to identify why tasks might be failing during deployment.
ECS only retains stopped task information for about 1 hour. Check stopped tasks promptly during troubleshooting.
View container logs for failed tasks
Inspect CloudWatch logs for containers that failed health checks or crashed during startup.
If the container crashes immediately, check for missing environment variables, invalid entrypoint commands, or insufficient memory allocation in the task definition.
Roll back if deployment fails
If the circuit breaker has not auto-rolled back, manually revert to the previous task definition revision.
Enable the deployment circuit breaker with rollback in your service configuration to automatically revert failed deployments.
Full Script
FAQ
Discussion
Loading comments...