Stop 13 · Infrastructure as Code & CI/CDProjects · 2/2

CI/CD Pipeline to ECS With GitHub Actions

Part of the AWS Roadmap

In short

Push to main, and a few minutes later the new version is live, tested and rollback-ready. Building this pipeline end to end is one of the most convincing things you can show in a cloud or DevOps interview.

A project where every push to main runs tests, builds a Docker image, pushes it to ECR and updates an ECS Fargate service, using OIDC instead of stored keys and a manual approval before production.

The jaadu in overalls signs a clipboard as a shiny new train coach rolls out of a factory line past several work stations.

Think of it like this

The Vande Bharat production line

At the coach factory in Chennai, each new coach passes fixed stations: frame, wiring, interiors, a test run on the track, and finally a sign-off by an inspector before it joins a real train. Nothing skips a station, and a failed test sends it back. Your pipeline is that line: test, build, push, approve, deploy.

Watch it happen

What happens after git push

Test
OIDC login
Build and push
Approval
Deploy to ECS

1/5The test job runs unit tests. If they fail, nothing else runs.

The big ideas

What you need to know

Separate jobs

A test job and a deploy job that needs: test. Pull requests run tests only, and pushes to main deploy.

Environments for approval

A GitHub environment called production with required reviewers adds a human gate, and the OIDC sub can be pinned to it.

Immutable image tags

Tag with github.sha so every deploy maps to exactly one commit, and rolling back means redeploying an older tag.

Wait for stability

Let the deploy step wait for the service to become stable so the workflow fails if the new tasks never get healthy.

See it in code

Walk through the code

yaml
1jobs:2  test:3    runs-on: ubuntu-latest4    steps:5      - uses: actions/checkout@v46      - run: npm ci && npm test7 8  deploy:9    needs: test10    if: github.ref == 'refs/heads/main'11    runs-on: ubuntu-latest12    environment: production13    permissions: { id-token: write, contents: read }14    steps:15      - uses: actions/checkout@v416      - uses: aws-actions/configure-aws-credentials@v417        with:18          role-to-assume: arn:aws:iam::111122223333:role/github-deploy-shop19          aws-region: ap-south-120      - id: ecr21        uses: aws-actions/amazon-ecr-login@v222      - id: build23        run: |24          IMAGE=${{ steps.ecr.outputs.registry }}/shop-api:${{ github.sha }}25          docker build -t $IMAGE . && docker push $IMAGE26          echo "image=$IMAGE" >> $GITHUB_OUTPUT27      - id: taskdef28        uses: aws-actions/amazon-ecs-render-task-definition@v129        with:30          task-definition: taskdef.json31          container-name: api32          image: ${{ steps.build.outputs.image }}33      - uses: aws-actions/amazon-ecs-deploy-task-definition@v234        with:35          task-definition: ${{ steps.taskdef.outputs.task-definition }}36          cluster: shop37          service: shop-api38          wait-for-service-stability: true

1/6Tests run first, on every push and pull request.

The jobs section of .github/workflows/deploy.yml, using AWS's official actions. The trigger is on: push to main plus pull_request.

Save yourself the pain

Common mistakes

Oops

Deploying from every branch and pull request.

Do this instead

Run tests everywhere but deploy only from main, and only after an approved environment gate for production.

Oops

Ending the workflow as soon as update-service is called.

Do this instead

Wait for service stability. Otherwise a green tick can hide a deploy that is crash-looping.

Your mission

Ship the pipeline

~120 min

Quick check

Why tag images with the commit SHA rather than latest?

Go deeper

  1. 1Use a GitHub environment with a required reviewer for the production deploy step.
  2. 2Tag images with the Git commit SHA instead of latest.
  3. 3Break a test on purpose and show the pipeline stops before deploying.

More projects at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge