Blog / CI/CD
Build a Zero-Downtime CI/CD Pipeline on AWS with Terraform and GitHub Actions
Shipping should be boring, one merge, tested, deployed, with a rollback that is one click away. Here is a battle-tested CI/CD pipeline on AWS that takes every commit to production with zero downtime.
The pipeline in five stages
- Build & test on GitHub Actions, run on every pull request.
- Package the app as a Docker image and push it to Amazon ECR, tagged with the git SHA.
- Provision infrastructure with Terraform, reviewed and versioned, no console clicking.
- Deploy blue/green to ECS Fargate or EKS, so the new version is health-checked before it takes traffic.
- Observe with CloudWatch and alerts, and keep the previous version ready for instant rollback.
1. Build and test on every push
# .github/workflows/deploy.yml
name: deploy
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions: { id-token: write, contents: read }
steps:
- uses: actions/checkout@v4
- run: make test
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1Use GitHub's OIDC to assume an IAM role, no long-lived AWS keys in secrets. That one change removes the most common credential-leak risk in CI.
2. Immutable images, tagged by commit
Tag every image with the git SHA (not latest). You always know exactly what is running, and a rollback is just re-pointing the service at the previous tag.
3. Infrastructure as Code with Terraform
Define the cluster, service, load balancer and networking in Terraform with remote state and reusable modules. Every change is a reviewed pull request, and new environments spin up identically in minutes.
4. Blue/green deploys = zero downtime
With ECS + CodeDeploy (or Argo Rollouts on EKS), the new "green" version comes up alongside the live "blue" one, passes health checks, then traffic shifts over. If anything looks wrong, traffic shifts back automatically. Users never see a blip.
A deploy you are afraid to run on a Friday is a process problem, not a courage problem. Automate the fear away.
5. Observe and roll back fast
- Dashboards for latency, error rate and saturation.
- Alerts that page you before users notice.
- One-command rollback to the last known-good image tag.
Key takeaways
- Test on every PR; deploy on merge to main.
- Use OIDC roles, never store AWS keys in CI.
- Immutable, SHA-tagged images make rollback trivial.
- Terraform for reviewed, reproducible infrastructure.
- Blue/green deploys give true zero-downtime releases.
Want this pipeline in your stack?
I build production CI/CD pipelines on AWS with Terraform and blue/green deploys. Tell me your setup and I'll send a clear plan with a fixed quote, no obligation.
Get a free DevOps audit →