Task roles, networking and rollbacks
Two roles, two responsibilities
The task execution role authorizes supported infrastructure actions such as pulling private ECR images, sending configured logs and retrieving startup secrets. The task role grants the application permissions it needs at runtime, such as reading a specific S3 object prefix. Grant only necessary actions and resources. Both roles use appropriate ECS task trust policies, but they serve different callers. Never put access keys or secret values in task definitions, images or logs. An operator also needs separate deployment permissions, including permission to pass only approved roles when required.
Private task networking
Fargate requires awsvpc network mode. A task receives a network interface and its own private IP in the selected VPC subnet. For this IPv4 example use private task subnets, no public IP, an ALB with an IP target group and a task security group allowing port 8080 only from the ALB security group. The application must listen on the intended interface and port. The ALB accepts HTTPS according to the design; authentication remains a separate application concern. Private tasks still need a working path to ECR, S3 image layers, logs and other dependencies using suitable VPC endpoints or controlled outbound routing. DNS and endpoint policies must also work.
Logs, discovery and secrets
Use structured logs with a request ID and a configured retention period; do not log secret values. ECS service discovery with AWS Cloud Map can expose private task addresses through DNS. ECS Service Connect is another service communication option; verify its requirements separately. If a secret is injected into an environment variable at startup, rotating the secret does not refresh existing containers automatically. Start replacement tasks or use an application design that retrieves and refreshes secrets securely. Environment variables can be visible to processes and debugging tools; limit access.
Health, rolling deployments and rollback
For a rolling ECS deployment with desired count 2, minimumHealthyPercent 100 and maximumPercent 200 permit two healthy old tasks to remain while up to two new tasks start, if capacity is available. The minimum healthy count rounds up and maximum running/pending count rounds down. Container health and ALB target health are different checks; allow a measured startup grace period. Configure the rolling deployment circuit breaker with rollback enabled; it can return to the last completed deployment if a failure is detected and a completed deployment exists. Other strategies include blue/green, linear and canary; they have different prerequisites. Rollback does not undo a database migration or restore lost data. Keep compatible schema changes and a recovery plan.
Troubleshoot and practice safely
A new revision never becomes healthy. First distinguish startup failures from health failures: inspect synthetic service events, stopped reasons, container exit status, target health and relevant log records. Check image availability, architecture, execution role, network path, port and health path before changing anything. Use the offline fixture to compute deployment bounds and choose a rollback candidate. For an optional authorized lab, preapprove region, resource counts and cost, use private administration, then remove only lab-owned services, tasks, load balancers, log groups and other chargeable resources according to retention rules. Verify cleanup independently. No cloud account is required for this chapter.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Task roles, networking and rollbacks — knowledge check
Apply the lesson to offline ECS scenarios.
Which role grants the bookstore application runtime read access to S3?
What target type is appropriate for the example Fargate service behind an ALB?
A startup-injected secret is rotated. What should the operator arrange?
For desired count 2 and rolling bounds 100% minimum, 200% maximum, what is the upper task count?
The new rolling deployment fails and the prior deployment completed. What can enabled rollback restore?