Chapter 89: Amazon ECS for DevOps
89.10 Lab — Fargate service from an ECR image
Story. You are helping a Zerodha-style API team train juniors. Real Fargate and ALB spend money (approximate — check pricing). In class you walk the full shape: Dockerfile → ECR → task definition → Fargate service → logs. Create resources only in a funded lab account your teacher names, and delete them the same day.
Lab steps
- Build a tiny HTTP app image locally (any language you already use). Expose port 8080 and a
/healthzthat returns 200. - Create an ECR repository
pay-api-labinap-south-1(or skip create if the teacher gives one). - Login, tag, and push the image. Copy the image URI.
- Create an IAM task execution role and a tight task role (even if the app needs no AWS APIs yet — practice the split).
- Register a Fargate task definition: CPU 256, memory 512,
awsvpc, awslogs to/ecs/pay-api-lab, both role ARNs, container port 8080. - Create cluster
shop-labif needed. Create a Fargate service with desired count 1 in private subnets (or public only if the lab design requiresassignPublicIp=ENABLED— follow the teacher). - Optional: attach an ALB target group and health check on
/healthz. - Run
aws ecs describe-servicesuntil runningCount is 1. Tail CloudWatch logs. - Push a second tag, register revision 2,
update-service, confirm a new deployment. - Delete the service, task definitions you created, load balancer pieces, and the image repo if policy allows — stop charges the same day.
What good looks like
- You can explain cluster vs task definition vs service in one minute.
- You never pasted real AWS access keys into Git or a lesson file.
- Logs appear in CloudWatch without SSH.
- You know approximate cost levers: Fargate vCPU/memory time, ALB-hours, NAT, log retention — and you verify on AWS pricing pages.
- Teardown is part of the lab, not an afterthought.
Funded account only. Delete lab ECS services and ALBs the same day. Local docker run is fine when AWS is not funded.
फक्त funded account. Lab ECS services आणि ALB तोच दिवस delete करा. AWS नसेल तर local docker run चालेल.
सिर्फ funded account. Lab ECS services और ALB उसी दिन delete करें. AWS न हो तो local docker run ठीक है.
Did you understand? Let us try it once more.