awscli等で名前付きプロファイル名で認証したいと思い、GitHub Actionsでどうやるか試行錯誤して、以下の方法で実現できたので書いておきます。
env:
AWS_ACCOUNT_ID: 123456789012
AWS_REGION: ap-northeast-1
AWS_IAM_ROLE: your-github-actions-role
AWS_PROFILE_NAME: profile_name
jobs:
dummy:
name: dummy
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
# Refs: https://github.com/aws-actions/configure-aws-credentials
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@master
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.AWS_IAM_ROLE }}
role-session-name: GitHubActions-${{ github.run_id }}
aws-region: ${{ env.AWS_REGION }}
- name: Set named credentials
run: |
aws configure set aws_access_key_id ${AWS_ACCESS_KEY_ID} --profile ${{ env.AWS_PROFILE_NAME }}
aws configure set aws_secret_access_key ${AWS_SECRET_ACCESS_KEY} --profile ${{ env.AWS_PROFILE_NAME }}
aws configure set aws_session_token ${AWS_SESSION_TOKEN} --profile ${{ env.AWS_PROFILE_NAME }}
# AWS認証がどのIAM権限で行われているかチェック用 (名前付きプロファイルを指定している)
- name: Call get-caller-identity to check AWS IAM
run: |
aws sts get-caller-identity --profile ${{ env.AWS_PROFILE_NAME }}