Last active
October 15, 2021 00:45
-
-
Save mamemomonga/0dad2b7a83e3655d2faa821dfc2b52e1 to your computer and use it in GitHub Desktop.
awscliでMFA認証を行う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
# 事前に名前付きプロファイルとして aws config --profile=プロファイル で登録しておく | |
# aws sts get-caller-identity でアカウントナンバー(Account)を確認する | |
BASE_PROFILE="プロファイル" | |
MFA_ACCOUNT_ID="AWSアカウントナンバー" | |
MFA_USERNAME="IAMユーザ名" | |
read -p "$BASE_PROFILE MFA Token: " MFA_TOKEN | |
CREDENTIALS=$( aws sts get-session-token --serial-number arn:aws:iam::$MFA_ACCOUNT_ID:mfa/$MFA_USERNAME --token-code $MFA_TOKEN --profile=$BASE_PROFILE ) | |
echo "以下をコピーペーストしてください" | |
echo "--- ここから ---" | |
echo 'export AWS_ACCESS_KEY_ID="'$( echo $CREDENTIALS | jq -r .Credentials.AccessKeyId )'"' | |
echo 'export AWS_SECRET_ACCESS_KEY="'$( echo $CREDENTIALS | jq -r .Credentials.SecretAccessKey )'"' | |
echo 'export AWS_SESSION_TOKEN="'$( echo $CREDENTIALS | jq -r .Credentials.SessionToken )'"' | |
echo 'export AWS_DEFAULT_REGION="ap-northeast-1"' | |
echo "--- ここまで ---" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment