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

AWS CLIを推奨設定(IAM Identity Center)で実行する

Last updated at Posted at 2025-03-11

はじめに

現在、AWS CLIを使用する際は、IAM Identity Centerにて短期認証情報を使用することが推奨となっています。
IAMユーザーのアクセスキーを発行する形でしかAWS CLIを使用したことがなかったため、推奨される形での手順を実施します。

設定手順

今回はIAM Identity Centerにて事前にユーザー及びユーザーグループを作成した状態から進めます。

前提条件

  • AWS CLIがインストールされていること
  • IAM Identity Center 内で SSO 認証へのアクセス権があること

1. aws configure ssoの実行に必要な値を収集

IAM Identity Centerのダッシュボードから設定の概要を確認し、以下の値を控えておく

  • リージョン
  • AWS access portal URL
sso_setting

2. aws configure sso でプロファイルを設定

任意のターミナルで aws configure ssoコマンドを実行し、プロファイルの設定を行う。
SSO start URL と SSO region には手順1で確認した値を入力する

$ aws configure sso
SSO session name (Recommended): my-sso
SSO start URL [None]: https://my-sso-portal.awsapps.com/start
SSO region [None]: ap-northeast-1
SSO registration scopes [None]: sso:account:access
実行例
PS C:\Users\test> aws configure sso
SSO session name (Recommended): my-sso
SSO start URL [None]: https://d-xxxxxxxxxx.awsapps.com/start
SSO region [None]: ap-northeast-1
SSO registration scopes [sso:account:access]: sso:account:access

3. ブラウザからの認証

デフォルトのブラウザが開かれ、サインインプロセスが実施される。
ターミナルで表示されたコードと一致していたら、「確認して続行」を押下する。
sso_setting

ターミナルの表示例
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://d-xxxxxxxxxx.awsapps.com/start/#/device

Then enter the code:

XJQL-ZXMP

その後、アクセス許可メッセージが表示されたら、「アクセスを許可」を押下する。

sso_setting

4. CLIの環境設定

ターミナルに戻り、AWSアカウントや使用するIAMロール、プロファイルの設定を行う

There are 2 AWS accounts available to you.
> DeveloperAccount, developer-account-admin@example.com (123456789011) 
  ProductionAccount, production-account-admin@example.com (123456789022)

Using the account ID 123456789011
There are 2 roles available to you.
> ReadOnly
  FullAccess

CLI default client Region [None]: ap-northeast-1
CLI default output format [None]: json
CLI profile name [123456789011_ReadOnly]: my-dev-profile
実行例
The only AWS account available to you is: 123456789123
Using the account ID 123456789123
The only role available to you is: AdministratorAccess
Using the role name "AdministratorAccess"
CLI default client Region [None]: ap-northeast-1
CLI default output format [None]: json
CLI profile name [AdministratorAccess-123456789123]: prod-admin

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

aws s3 ls --profile prod-admin

CLI profile name に default を指定するとデフォルトプロファイルとなる。

5. CLIの使用

セットアップが完了したため、AWS CLIでコマンドの実行確認を行う。

aws s3 ls --profile profile_name

S3バケットの一覧がリスト表示された場合は、正常に設定が行われている。
※使用するユーザーにS3のリスト権限がない場合は権限のある別のコマンドで確認すること。

ログインとログアウトの手順

有効期限を超過したりログアウトをしたりした場合は、AWS CLIのコマンドがエラーとなる。

# aws s3 ls

Error loading SSO Token: Token for my-sso does not exist

その際は下記を実施し、ログインする。

ログイン

aws sso login を実行し、ブラウザから認証を行う。

# aws sso login --profile profile_name
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://d-xxxxxxxxxx.awsapps.com/start/#/device

Then enter the code:

XZZV-LKMB

ターミナルで表示されたコードと一致していたら、「確認して続行」を押下する。

sso_setting

アクセス許可メッセージが表示されたら、「アクセスを許可」を押下する。
sso_setting

その後ターミナルに成功メッセージが表示されればログインの完了

Successfully logged into Start URL: https://d-xxxxxxxxxx.awsapps.com/start

ログアウト

aws sso logoutを実行し、ログアウトする

# aws sso logout

参考文献

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?