GitHub Actions to AWS
Build and deploy to AWS from GitHub Actions using OIDC roles, reusable workflows, environments with approvals and caching.
Intermediate · about 6 hours · difficulty 3/5
Learn first: CI/CD Concepts and Pipeline Design, STS, Assume Role and Federation, Docker and Container Images
GitHub Actions is the most common CI/CD tool for startups and open-source projects, and it lives right next to your code. It is our recommended pick because it is free for public repos and has a generous free allowance for private ones.
Workflow basics
- Workflows are YAML files in .github/workflows, triggered by events (push, pull_request, workflow_dispatch, schedule).
- Jobs run on runners and contain steps; jobs can depend on each other with needs.
- Actions from the marketplace do common tasks: actions/checkout, actions/setup-node, docker/build-push-action.
Deploying to AWS safely
- Use aws-actions/configure-aws-credentials with OIDC: the workflow assumes an IAM role, no stored keys.
- Scope the role's trust policy to your repo and branch or environment.
- Official actions exist for ECR login, ECS task definition updates and deployments.
Production features
- Environments (staging, production) with required reviewers and environment-specific secrets and roles.
- Reusable workflows and composite actions to avoid copy-paste across repos.
- Caching dependencies and Docker layers to speed up builds.
- Concurrency groups so two deploys to production never run at once.
- Pin third-party actions to a commit SHA for supply-chain safety.
Pitfalls
- Storing AWS access keys as repository secrets when OIDC is available.
- Running deploy jobs on pull requests from forks.
- Huge single-job workflows that are hard to debug.
You are ready to move on when a push to main builds your image, pushes it to ECR and deploys it, with production gated behind a manual approval.
Key concepts
- Workflows, jobs and steps
- Triggers and events
- OIDC with configure-aws-credentials
- Environments and approvals
- Reusable workflows
- Caching
- Concurrency groups
- Pinning actions to SHAs
Other options for this step
- AWS CodePipeline and CodeBuild: Build AWS-native pipelines with CodePipeline, CodeBuild and CodeDeploy, useful in companies that keep all tooling inside AWS accounts.
Mini project
Create a workflow that on pull request runs tests and terraform plan, and on merge to main builds your image, pushes to ECR and updates an ECS service or Lambda, using OIDC only. Gate production behind an environment approval. Use the free GitHub Actions minutes and tear down the AWS side after testing.
Check yourself
What condition in the IAM trust policy stops a workflow in someone else's repository from assuming your deploy role?
Free resources
- GitHub Actions documentation (GitHub)
- configure-aws-credentials action (AWS)
- Configuring OpenID Connect in AWS (GitHub)