3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub ActionsでAWS IAMロール認証を名前付きプロファイルとして利用する

Last updated at Posted at 2022-12-07

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 }}
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?