Day 3 – Deploy Containers to ECS
Today's Focus
Deploy your containerised application to a managed container service (ECS Fargate or Cloud Run) and connect it to the load balancer.
Tasks
- Push your Docker image from Week 7 to ECR (Elastic Container Registry) or GCR: create the registry with Terraform (
aws_ecr_repository), authenticate Docker withaws ecr get-login-password | docker login, tag your image with the registry URI, and push. - Write a Terraform ECS Fargate task definition: specify the container image (ECR URI), CPU and memory, environment variables (from a
aws_secretsmanager_secret_versionor SSM parameter — not hard-coded), and the IAM task execution role. - Create an ECS Service that runs 2 instances of your task, attached to your VPC's private subnet, with the
app-sgsecurity group. Register the service with the ALB target group from Tuesday. - Wait for the deployment to stabilise:
aws ecs describe-services --cluster your-cluster --services your-serviceshould showrunningCount: 2. Thencurl http://<alb-dns>/healthshould return{"status": "ok"}. - Simulate a deployment: update your Docker image (change a response message), push a new tag, update the task definition image tag in Terraform, and
terraform apply. Watch ECS perform a rolling update — old tasks drain before new ones are registered. - Enable container logging: add a
logConfigurationblock pointing to CloudWatch Logs. After the deployment, find your container logs in the AWS console and confirm application startup messages appear.