LoginSignup
8
4

More than 5 years have passed since last update.

AWS CLIを使って、MFAのついたアカウントでAssumeRoleする

Last updated at Posted at 2018-10-17

概要

MFAが有効になったIAMユーザーにRoleをアタッチするときにちゃんとドキュメント読んでなくてハマったのでメモしとく

やり方

AssumeRoleに使うロールと、自分のプロファイルは~/.aws/config~/.aws/credentialsに入れておく

~/.aws/config
[profile user] # 自身のユーザー
region=リージョン
output=json

[profile assumerole] # 対象のロール
role_arn=arn:aws:iam::xxxxxx:role/role-name
mfa_serial=arn:aws:iam::xxxxxx:mfa/username
source_profile=user
region=リージョン
~/.aws/credentials
[user]
aws_access_key_id=XXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

で、叩きたいAPIを叩くとMFAのトークンを入れるように聞かれる。

$ aws 使いたいコマンド --profile assumerole
Enter MFA code for arn:aws:iam::xxxxxx:mfa/username:

入れると結果が返ってくるようになる

8
4
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
8
4