GitHub Actions Deploy to AWS ECS Workflow

Generate an ECS deploy workflow with ECR push and task definition update

Build a GitHub Actions workflow that logs into Amazon ECR, builds and pushes a Docker image, renders a new ECS task definition, and deploys to ECS Fargate using OIDC role assumption — no long-lived AWS keys required.

Why use OIDC instead of access keys?

OIDC lets GitHub Actions assume an IAM role using short-lived credentials minted per run, so there are no long-lived AWS access keys stored in secrets to leak. It is AWS's recommended approach for CI and limits the blast radius of a compromise.

Deploying a container to AWS ECS Fargate from CI involves several precise steps: authenticating to ECR, building and tagging an image, pushing it, and registering a new task definition revision. This generator produces a complete GitHub Actions workflow that does all of that using OIDC role assumption, so no static AWS keys live in your repository.

How it works

The workflow uses the official AWS actions in a fixed order:

  1. aws-actions/configure-aws-credentials assumes your IAM role via GitHub’s OIDC token — short-lived credentials, no stored keys.
  2. aws-actions/amazon-ecr-login authenticates Docker to your private ECR registry.
  3. docker build and docker push create and upload the image tagged with the commit SHA.
  4. aws-actions/amazon-ecs-render-task-definition injects the new image into your task definition JSON.
  5. aws-actions/amazon-ecs-deploy-task-definition registers the revision and updates the service, waiting for stability.

Tips and notes

  • Grant the IAM role only ecr:* on the repository plus the ECS and IAM PassRole permissions it needs — least privilege.
  • Tagging by commit SHA makes rollbacks trivial: re-deploy a prior task definition revision pointing at the old SHA.
  • Set wait-for-service-stability: true so the job fails if the new tasks never reach a healthy steady state.
  • Keep a base task definition JSON file in your repo so the render step has something to patch.