A GitHub Actions job fails with "Error: Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity". Fix it.

AdvancedHands-onLive debugging tasks
Answer

Check, in order:

  1. The workflow has permissions: id-token: write.
  2. The account has an IAM OIDC provider for https://token.actions.githubusercontent.com with audience sts.amazonaws.com.
  3. The role trust policy matches the token's sub claim:
"Condition": {
  "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" },
  "StringLike":   { "token.actions.githubusercontent.com:sub": "repo:org/app:ref:refs/heads/main" }
}
  1. If the job uses environment: production, the sub is repo:org/app:environment:production, not the branch form.

Key trick → The environment-versus-branch sub format is the usual culprit. The job worked until someone added environment: to it.

All Real-World Interview questions Roadmap: Interview readiness

More on Live debugging tasks