Long-lived AWS access keys stored in GitHub secrets are a standing risk: they can leak, they are hard to rotate, and they grant access even when no deployment is running. GitHub Actions OIDC to AWS replaces those keys with short-lived credentials issued only for a specific workflow run, a specific repository, and a specific branch. This guide shows how to set up GitHub Actions OIDC to AWS end to end, with an IAM role that trusts only your repository.
By the end, your workflow will assume an AWS role using an identity token from GitHub, deploy without any stored secret, and fail closed if any other repository or branch tries to use the role. The same pattern works for Terraform, the AWS CLI, and container deployments.

Prerequisites for GitHub Actions OIDC to AWS
You need a GitHub repository with Actions enabled, an AWS account with permission to create IAM identity providers and roles, and the AWS CLI installed locally for verification. No AWS access keys are needed in GitHub at any point, which is the whole point of this setup.
Understand the trust model before you start: GitHub’s OIDC provider issues a token that asserts the repository, branch, and workflow. AWS verifies that token against an identity provider you register, then checks the role’s trust policy. If either check fails, no credentials are issued.
Step 1: Register GitHub as an OIDC Identity Provider in AWS
Create the identity provider once per AWS account. Use the AWS CLI or the console, with GitHub’s issuer URL and the standard audience for Actions:
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com \
--thumbprint-list 6938fd4d98bab03faadb97b34396831e3780a1
The thumbprint is GitHub’s documented root certificate thumbprint for the OIDC provider. If AWS reports that the provider already exists, skip this step; creating a duplicate is unnecessary and will fail. Note the provider ARN for the next step.
Step 2: Create an IAM Role with a Scoped Trust Policy
Create a role whose trust policy allows only your repository and branch to assume it. The StringLike condition on token.actions.githubusercontent.com:sub is the critical control: it binds the role to repo:OWNER/REPO:ref:refs/heads/main, so pull requests, other branches, and other repositories are rejected:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:myorg/myapp:ref:refs/heads/main"
}
}
}
]
}
Replace the account ID, owner, repository, and branch with your own values, then create the role and attach only the permissions the deployment actually needs. A deployment that only uploads to one S3 bucket should not have administrator access, and a role used by production should be separate from a role used by staging.
aws iam create-role --role-name github-deploy-myapp \
--assume-role-policy-document file://trust-policy.json
aws iam attach-role-policy --role-name github-deploy-myapp \
--policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess
Prefer a custom least-privilege policy over a managed full-access policy in production. The example above uses a managed policy only to keep the setup readable; narrow it before real use.
Step 3: Configure the GitHub Actions Workflow
In your workflow, request the id-token: write permission, which is what allows the job to obtain an OIDC token. Without it, the credential configuration step fails with a permissions error. Then use the official configure-aws-credentials action with the role ARN:
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/github-deploy-myapp
aws-region: us-east-1
- run: aws sts get-caller-identity
- run: aws s3 sync ./dist s3://myapp-bucket/ --delete
The aws sts get-caller-identity step is a cheap smoke test: it confirms the assumed role and account before any destructive command runs. If it shows the wrong role, stop and fix the role ARN before deploying anything.
Step 4: Test, Restrict, and Rotate Safely
Push a change to main and watch the workflow run. Confirm in CloudTrail that the AssumeRoleWithWebIdentity event records your repository and branch, and that the session duration is short. The default session for this action is one hour, which is appropriate for most deployments.
Next, verify the negative cases. A workflow run from a feature branch should fail to assume the role if the trust policy is scoped to main. A run from a different repository should fail too. If either succeeds, your trust policy is too broad and must be tightened immediately.
Rotation is now a non-event: there is no stored key to rotate. If a role needs to be revoked, edit its trust policy or delete the role, and all future assumptions stop. Audit role usage regularly with IAM Access Analyzer and CloudTrail, and remove roles for repositories that no longer deploy.
Troubleshooting GitHub Actions OIDC to AWS
The most common error is “Not authorized to perform sts:AssumeRoleWithWebIdentity”, which almost always means the trust policy subject does not match the actual workflow. The subject includes the exact repository, ref type, and branch, so a tag push, a pull request event, or a renamed branch all produce different subjects. Check the workflow’s ref and add a second condition value only if you genuinely need that ref to deploy.
Another common error is “An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation” combined with a missing id-token permission. Add id-token: write at the job or workflow level, not just in a step, because permissions are evaluated for the whole job.
If the OIDC provider creation fails with an already-exists error, list existing providers with aws iam list-open-id-connect-providers and reuse the existing one. Multiple accounts and regions do not need multiple GitHub providers.
Conclusion
GitHub Actions OIDC to AWS removes the weakest link in CI deployments: the stored cloud credential. With a registered provider, a tightly scoped trust policy, and the id-token permission, every deployment gets fresh, short-lived credentials that exist only for that run. Adopt it for one repository first, verify the negative cases, then roll it out to the rest. For related automation patterns, see our guides on GitHub Actions reusable workflows and IAM roles for EC2. The official GitHub OIDC documentation for AWS covers additional subject patterns for environments and pull requests.