Quick Start with GitHub OIDC (Recommended)
mainThe recommended way to authenticate to AWS from GitHub Actions is using OpenID Connect (OIDC). This method provides temporary credentials and avoids the need to store long-lived secrets in GitHub.
To set this up:
- Create an IAM Identity Provider in your AWS account for GitHub OIDC.
- Create an IAM Role with a trust policy that allows GitHub Actions to assume it. The trust policy must use
sts:AssumeRoleWithWebIdentityand include a condition matching your GitHub organization, repository, and branch/environment. - Attach Permissions to the IAM Role for the specific AWS resources your workflow needs to access.
- Configure your Workflow by setting
permissions: id-token: writeand using theaws-actions/configure-aws-credentialsaction withrole-to-assumeandaws-region.
# Need ID token write permission to use OIDC
permissions:
id-token: write
jobs:
run_job_with_aws:
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v6.2.3
with:
role-to-assume: <Role ARN you created in step 2>
aws-region: <AWS Region you want to use>
- name: Additional steps
run: |
# Your commands that require AWS credentials
aws sts get-caller-identity