AWS Builder Center

Safer ECS Releases with Image Digests, Canary Alarms, and Fast Rollback

A practical ECS Fargate deployment pattern combining GitHub OIDC, immutable ECR images, CodeDeploy blue/green releases, and CloudWatch alarms, with a checklist for security, rollback, and temporary capacity costs.

Student

Why release safety needs both prevention and rollback

An ECS task can start successfully while the application returns errors, times out on a dependency, or fails only under live traffic. A safer release pipeline limits what can be deployed, exposes a small share of traffic first, and rolls back when evidence shows the new version is unhealthy.

Reference flow

  1. GitHub Actions authenticates to AWS with OIDC and assumes a narrowly scoped deployment role.
  1. The workflow tests and scans a container, pushes it to Amazon ECR, and records the immutable image digest. Deploy the digest, not a mutable  latest  tag.
  1. ECS runs the task on Fargate behind an Application Load Balancer. CodeDeploy shifts traffic with a blue/green deployment.
  1. CloudWatch alarms watch the new target group during the canary window. If an alarm trips or health checks fail, CodeDeploy stops the shift and restores the prior task set.

Make the build identity and artifact explicit

Use GitHub OIDC instead of long-lived AWS keys. In the IAM role trust policy, constrain the audience and subject to the expected repository and branch or release environment. Give the role only the ECR actions needed to push to the application repository and the deployment actions needed for this ECS service. Keep build permissions separate from runtime permissions.
After tests and image scanning pass, record the commit SHA, ECR digest, and workflow run in a release manifest. Pin the ECS task definition to that digest. This makes rollback reproducible and prevents a tag from changing between review and deployment. Store secrets in Secrets Manager or Parameter Store; grant the task role access only to the specific secret paths it needs.

Shift traffic in measured steps

Configure CodeDeploy with a canary or linear shift, such as 10 percent for five minutes followed by the remainder. Use target group health checks that test application readiness, not just whether a port accepts connections. Alarm on elevated ALB 5xx responses, request latency, unhealthy targets, and a sharp drop in successful requests. With sparse traffic, combine metrics with a short manual approval instead of treating a quiet canary as proof of health.
Set rollback alarms before deployment and verify that the deployment role can perform the rollback. Keep the previous task set available until the new one passes the observation window. For database changes, use an expand-and-contract migration: add compatible schema first, deploy code that supports both versions, then remove old fields later. A compute rollback cannot undo an incompatible data migration.

Security and operations checklist

  • Run containers as a non-root user where possible; make the root filesystem read-only and allow writable paths explicitly.
  • Separate the task execution role from the application task role, with narrow policies for each.
  • Log the deployment ID, task-definition revision, image digest, and rollback reason so incidents map to a specific artifact.
  • Test rollback in a non-production service and show canary metrics separately on dashboards.
  • Review stopped-task reasons and log streams before changing subnets or security groups; otherwise an infrastructure change can hide an application defect.

Cost and reliability trade-off

Blue/green deployment temporarily runs old and new capacity together. Budget for an extra task set during the shift; for a small service, that can be a large percentage increase. Check Fargate quotas and capacity headroom so the rollout is not blocked. A short canary limits exposure but adds deployment time and monitoring needs. Choose traffic steps based on how quickly alarms detect customer impact, and show the temporary capacity cost in the release plan.
The goal is not to make releases risk-free. It is to make each change traceable, limit initial exposure, and give the service a tested way to stop when the evidence says the new version is unhealthy.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article