aws-mfaをインストールする
example-long-termというプロファイルを作る。accesskey等はIAM作成時に作ったものでOK。
% aws configure --profile example-long-term
AWS Access Key ID [None]: XXXXXXX
AWS Secret Access Key [None]: XXXXXX
Default region name [None]:
exampleというプロファイルを作る。accesskey, secretは空でOK。
% aws configure --profile example
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: ap-northeast-1
Default output format [None]: json
example-long-termのaws_mfa_deviceにMFAのARN(aws consoleのIAMから確認)を設定する。
% vim ~/.aws/credentials
[example-long-term]
aws_access_key_id = XXXXX
aws_secret_access_key = XXXX
aws_mfa_device = XXXX
exampleプロファイルを更新する。MFAのワンタイムキーを要求されるので入力する。
% aws-mfa --profile example
INFO - Validating credentials for profile: example
WARNING - Your existing credentials are missing or invalid, obtaining new credentials.
Enter AWS MFA code for device [arn:aws:iam::xxxx/xxxxx] (renewing for 43200 seconds):xxxxxx
INFO - Fetching Credentials - Profile: example, Duration: 43200
INFO - Success! Your credentials will expire in 43200 seconds at: 2021-11-19 17:07:06+00:00