Keel

How should a small team set up CI/CD for Amazon ECS?

By the Keel team · Last checked · 4 min read

Short answer

A small team should set up CI/CD for Amazon ECS as one pipeline: run tests on every pull request, build the image once and push it to ECR, run database migrations as a separate step, then deploy to ECS with the circuit breaker and rollback on, and fail the job if ECS rolled back. Use OIDC so GitHub Actions never stores AWS keys.

What does a good CI/CD pipeline for Amazon ECS look like?

A good CI/CD pipeline for Amazon ECS is short and boring: test, build once, migrate, deploy, verify.

Each stage either passes or stops the release, and nothing reaches production that was not built and tested by the pipeline itself.

Stages of a small-team CI/CD pipeline for Amazon ECS
StageWhat happensStops the release if
TestUnit and integration tests on every pull requestAny test fails
BuildBuild one image, tag it with the commit, push to ECRThe build or push fails
MigrateRun database migrations as a one-off ECS taskThe migration task exits with an error
DeployUpdate the ECS service with circuit breaker and rollback onECS cannot reach a healthy state
VerifyCheck the new task definition is live and healthyECS rolled back or health checks fail

Which CI/CD tool should a small team use for Amazon ECS?

For a small team whose code already lives on GitHub, GitHub Actions is usually the simplest CI/CD tool for ECS, because AWS publishes official actions for logging in to ECR, rendering task definitions and deploying to ECS.

AWS's own CodePipeline also works well, and makes more sense if you want everything inside AWS.

Whichever you choose, keep the pipeline definition in your repository, so changes to how you deploy are reviewed like any other code.

How should GitHub Actions authenticate to AWS for ECS deploys?

GitHub Actions should authenticate to AWS with OpenID Connect, which gives each workflow run short-lived credentials from an IAM role instead of storing long-lived AWS access keys as GitHub secrets.

Stored keys can leak and keep working until someone rotates them, so this is worth doing before anything else.

Scope the role to what the deploy needs: pushing to one ECR repository, registering task definitions, running the migration task and updating the ECS service. Restrict the role's trust policy to your repository and, ideally, to the main branch.

What does a GitHub Actions workflow for Amazon ECS look like?

A GitHub Actions workflow for ECS checks out the code, assumes the deploy role with OIDC, builds and pushes the image, renders a new task definition with that image, and deploys it while waiting for the service to stabilise.

The outline below shows the shape; add your own test and migration steps.

name: deploy
on:
  push:
    branches: [main]
permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/deploy
          aws-region: eu-west-2
      - id: ecr
        uses: aws-actions/amazon-ecr-login@v2
      - name: Build and push
        run: |
          IMAGE=${{ steps.ecr.outputs.registry }}/app:${{ github.sha }}
          docker build -t $IMAGE .
          docker push $IMAGE
          echo "IMAGE=$IMAGE" >> $GITHUB_ENV
      - id: render
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          task-definition: task-definition.json
          container-name: app
          image: ${{ env.IMAGE }}
      - id: deploy
        uses: aws-actions/amazon-ecs-deploy-task-definition@v2
        with:
          task-definition: ${{ steps.render.outputs.task-definition }}
          service: app
          cluster: production
          wait-for-service-stability: true

The account ID, region and names are placeholders. One step is still missing: checking that the deploy really succeeded, which the next section covers.

How do you make Amazon ECS deployments roll back safely?

Make ECS deployments roll back safely by turning on the deployment circuit breaker with rollback, adding CloudWatch alarms for errors, and failing the pipeline when ECS rolls back.

Without that last step, the deploy action can report success after a rollback, because the service ends up stable on the old version.

The guide to automatic ECS rollback with GitHub Actions shows the extra check step, and what a deployment health check should test covers the load balancer health check that decides whether a new task is healthy. Database migrations need their own care, covered in rolling back ECS after a migration.

Should a small team use rolling or blue/green deployments on Amazon ECS?

Most small teams should start with rolling deployments plus the circuit breaker, and move to blue/green when they want to test a new version before it takes real traffic.

Since July 2025, Amazon ECS has built-in blue/green deployments for services behind a load balancer or Service Connect, with lifecycle hooks for checks, a bake time and rollback without downtime.

Rolling deployments suit you when

  • You deploy small changes often.
  • Health checks catch most failures.
  • You want the simplest setup to run.

Blue/green suits you when

  • You want to test the new version before switching traffic.
  • A bad release is very costly, even for a few minutes.
  • You need a bake period before the old version is removed.

Is your Amazon ECS pipeline ready for frequent releases?

Tick each item that is true for your pipeline today.

  • Tests run on every pull request and block merging when they fail.
  • GitHub Actions uses OIDC, with no AWS keys stored as secrets.
  • Each image is built once and tagged with its commit.
  • Migrations run as their own step before the service updates.
  • The circuit breaker with rollback is on for every service.
  • The pipeline fails when ECS rolls a deployment back.

Decision point: Five or six ticks: you can ship several times a day with confidence. Three or fewer: fix the missing steps before increasing release frequency.

Sources

  1. GitHub Docs, Configuring OpenID Connect in Amazon Web Services (checked October 2026)
  2. GitHub, aws-actions/amazon-ecs-deploy-task-definition (checked October 2026)
  3. AWS docs, How the Amazon ECS deployment circuit breaker detects failures (checked October 2026)
  4. AWS docs, How CloudWatch alarms detect Amazon ECS deployment failures (checked October 2026)
  5. GitHub, amazon-ecs-deploy-task-definition issue 191: action should fail if the circuit breaker rolls back (checked October 2026)
  6. AWS, Amazon ECS enables built-in blue/green deployments (July 2025) (July 2025)
  7. AWS docs, Health checks for Application Load Balancer target groups (checked October 2026)

Keep reading

Keel is an AWS release and recovery operations service for SaaS teams of 3 to 15 developers, provided by Bargainn Services Ltd, a UK company registered at Companies House (16497746). Registered office: 3rd Floor, 86-90 Paul Street, London, EC2A 4NE, United Kingdom.