0
0

IAM Identity CenterユーザーのprofileをAWS CLIに登録する手順

Posted at

はじめに

AWS 初学者です。

AWS CLIの profile にIAM Identity Centerユーザーを登録する手順を備忘録としてまとめます。

この記事におけるバージョンは次のとおりです。

$ aws --version           
aws-cli/2.17.56 Python/3.12.6 Darwin/23.4.0 exe/x86_64

なおIAM Identity Centerユーザーは作成してある前提です。

また記事で登場するaws configure ssoコマンドは AWS CLI のバージョン2でしか利用できません。

バージョン1しかインストールされていない場合は公式ドキュメントの手順にしたがって事前にアップデートしましょう。

IAM Identity CenterユーザーのprofileをAWS CLIに登録する手順

aws configure ssoコマンドを実行し、流れに沿って入力していけばOK。

$ aws configure sso
SSO session name [default]: sample-profile
SSO start URL [None]: https://a-1234567a01.awsapps.com/start/
SSO region [None]: ap-northeast-1
SSO registration scopes [sso:account:access]: sso:account:access
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:

https://device.sso.ap-northeast-1.amazonaws.com/

Then enter the code:

ABCD-EFGH
The only AWS account available to you is: 123456789012
Using the account ID 123456789012
The only role available to you is: PowerUserAccess
Using the role name "PowerUserAccess"
CLI default client Region [ap-northeast-1]: ap-northeast-1
CLI default output format [json]: json
CLI profile name [PowerUserAccess-597088053766]: sample-profile

To use this profile, specify the profile name using --profile, as shown:

aws s3 ls --profile sample-profile
$ 

SSO registration scopesを入力後、ブラウザが起動します。

ターミナルのコード(ABCD-EFGH)とブラウザに表示されるコードが一致しているか確認し、問題なければ承認してください。

ターミナルに戻るとCLI default client Regionが入力できるようになっています。

登録が完了したら、ログインできることを確認しましょう。

$ aws sso login --profile sample-profile
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:

https://device.sso.ap-northeast-1.amazonaws.com/

Then enter the code:

ABCD-EFGH
Successfully logged into Start URL: https://a-1234567a01.awsapps.com/start/

aws sso loginコマンドを実行すると再びブラウザが立ち上がります。

ターミナルのコマンド(ABCD-EFGH)とブラウザに表示されるコードが一致しているか確認し、問題なければ承認してください。

ターミナルに戻ってSuccessfully logged into Start URL: 〇〇と表示されていれば成功です。

設定されたプロファイルは~/.aws/configファイルに保存されます。

必要に応じて直接編集することも可能です。

$ cat ~/.aws/config
[profile sample-profile]
sso_session = sample-profile
sso_account_id = 123456789012
sso_role_name = PowerUserAccess
region = ap-northeast-1
output = json
[sso-session sample-profile]
sso_start_url = https://a-1234567a01.awsapps.com/start/
sso_region = ap-northeast-1
sso_registration_scopes = sso:account:access

おわりに

AWSは公式ドキュメントが充実しているのですが、逆にありすぎて探すのに一苦労です。

逐一アウトプットして定着させていきます。

参考資料

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