Skip to content

OIDC with AWS

OIDC lets a job get short-lived AWS credentials without storing an access key in GitHub. Each run asks GitHub for a signed token, and AWS swaps it for temporary credentials. The token flow is the standard GitHub Actions one, so the workflow below is the usual one with a compiler.dev runs-on label. For a longer walk-through, see GitHub Actions OIDC to AWS.

1. Add GitHub as an identity provider in IAM. Provider URL https://token.actions.githubusercontent.com, audience sts.amazonaws.com.

2. Create a role with this trust policy. Replace 111122223333, ORG and REPO. The sub condition is what keeps other repositories and branches out, so always set it.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com" },
    "Action": "sts:AssumeRoleWithWebIdentity",
    "Condition": {
      "StringEquals": {
        "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
        "token.actions.githubusercontent.com:sub": "repo:ORG/REPO:ref:refs/heads/main"
      }
    }
  }]
}

3. Use the role in your workflow. The job needs id-token: write:

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: compiler-8cpu
    steps:
      - uses: actions/checkout@v4
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::111122223333:role/github-deploy
          aws-region: eu-west-2
      - run: aws sts get-caller-identity