GitHub Actions to AWS With OIDC
Part of the AWS Roadmap
In short
Long-lived AWS access keys pasted into GitHub secrets are one of the most common ways cloud accounts get compromised. With OIDC, your workflow gets short-lived credentials for each run and there are no keys to leak.
GitHub Actions can deploy to AWS without stored access keys by using OpenID Connect: the workflow gets a short-lived token, and an IAM role trusts tokens only from your repository and branch.

Think of it like this
The day pass at the factory gate
A contractor visiting a Chennai car plant doesn't get a permanent key. Each morning he shows his company ID, the gate checks it's from an approved company and the right job, and issues a day pass that stops working at sunset. GitHub's OIDC token is the company ID, the IAM role's trust policy is the gate's list, and STS issues the day pass.
Watch it happen
How a workflow gets AWS credentials
Request ID token
1/5Allowed because the workflow has permissions: id-token: write.
The big ideas
What you need to know
Identity provider in IAM
Add token.actions.githubusercontent.com as an OpenID Connect provider in IAM, once per account.
Tight trust policy
Require aud = sts.amazonaws.com and a sub that matches your repo and branch or environment. Without a sub condition, any GitHub repo could assume the role.
Least-privilege role
The role should only allow what the deploy needs, like pushing to one ECR repo and updating one ECS service.
No stored keys
Delete old AWS_ACCESS_KEY_ID secrets from the repo once OIDC works.
See it in code
Walk through the code
1name: deploy2on:3 push:4 branches: [main]5 6permissions:7 id-token: write # needed to request the OIDC token8 contents: read9 10jobs:11 deploy:12 runs-on: ubuntu-latest13 steps:14 - uses: actions/checkout@v415 16 - 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 21 - run: aws sts get-caller-identity22 23# Trust policy condition on the role:24# "StringEquals": {25# "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",26# "token.actions.githubusercontent.com:sub": "repo:rahul-dev/shop:ref:refs/heads/main" }1/5Run on every push to main.
A GitHub Actions workflow using the official AWS action. No secrets are referenced anywhere.
Save yourself the pain
Common mistakes
Oops
Using a wildcard sub like repo:* or leaving out the sub condition.
Do this instead
Pin it to repo:OWNER/REPO and a branch or environment, such as repo:rahul-dev/shop:environment:production.
Oops
Attaching AdministratorAccess to the deploy role 'for now'.
Do this instead
Start with exactly the permissions the deploy needs and add more only when a step fails for a clear reason.
Your mission
Keyless deploy
Quick check
Your workflow fails with 'Credentials could not be loaded' at the configure step. What's often missing?
Go deeper
- 1Add GitHub as an OIDC identity provider in IAM and create a role for one repository.
- 2Use the aws-actions/configure-aws-credentials action to assume the role in a workflow.
- 3Restrict the role's trust policy to the main branch of one repo.
More topics 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.