LoginSignup
0
0

AWS CLIとSSOでIAM Roleを切り替える設定手順

Posted at

はじめに

AWS CLIとAWS SSOを組み合わせて使用する際に、IAM Roleを切り替えて利用するケースがあります。
ここでは、その設定方法を備忘録として記載します。

この記事を読む前提条件として、AWS CLI v2が既にインストールされていることを前提とします。

1. SSOでログインする

まず、以下のコマンドを使用してSSOでログインします。

aws configure sso

ログイン成功後、~/.aws/configに以下のような設定が生成されます。

[profile profile1]
sso_start_url = https://my-sso-portal.awsapps.com/start/
sso_region = us-east-1
sso_account_id = 123456789012
sso_role_name = readOnly
region = ap-northeast-1
output = json

2. スイッチしたいロールを登録する

次に、使用したいロールにスイッチするため ~/.aws/configを編集します。

以下のように追記してください。

[profile profile1]
sso_start_url = https://my-sso-portal.awsapps.com/start/
sso_region = us-east-1
sso_account_id = 123456789012
sso_role_name = readOnly
region = ap-northeast-1
output = json

[profile rolename]
role_arn = arn:aws:iam::123456789012:role/rolename
credential_source = profile1

この設定により、profile1の認証情報を使用してrolenameロールに切り替えることができます。

3. 実行

設定が完了したら、以下のコマンドを使用して、新しいロールでAWSコマンドを実行できます。
-profileオプションには、設定したプロファイル名(この例ではrolename)を指定します。

aws s3 ls --profile rolename

まとめ

本記事では、AWS CLIとAWS SSOを組み合わせて使用する際に、IAM Roleを簡単に切り替える方法について解説しました。

参考文献

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