背景・目的
AWS CLIやSSO周りの設定について忘れぽいので、メモします。
実践
前提
- Macを利用しています
brew のインストール
-
下記のコマンドを実行し、インストールします
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
途中で下記が求められるのでEnter
Press RETURN/ENTER to continue or any other key to abort:
-
brewコマンドを実行し、下記のように表示されればOKです
$ brew Example usage: brew search TEXT|/REGEX/ brew info [FORMULA|CASK...] brew install FORMULA|CASK... brew update brew upgrade [FORMULA|CASK...] brew uninstall FORMULA|CASK... brew list [FORMULA|CASK...] Troubleshooting: brew config brew doctor brew install --verbose --debug FORMULA|CASK Contributing: brew create URL [--no-fetch] brew edit [FORMULA|CASK...] Further help: brew commands brew help [COMMAND] man brew https://docs.brew.sh $
aws cliのインストール
- 下記のコマンドを実行し、aws cliをインストールします
$ brew install awscli
- 3分程度でインストールが完了します
- awsコマンドを実行し、下記のように表示されればOKです
$ aws usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters] To see help text, you can run: aws help aws <command> help aws <command> <subcommand> help aws: error: the following arguments are required: command $
AWS SSOの設定
-
下記のコマンドを実行すると、SSO session nameが求められます
$ aws configure sso SSO session name (Recommended):my-sso
-
次に、SSOポータルを求められますので、指定します
SSO start URL [None]: https://xxxxxx.awsapps.com/start
-
次にリージョンが求められますので、指定します
SSO region [None]: ap-northeast-1
-
最後に、スコープが求められます
SSO registration scopes [sso:account:access]: sso:account:access
-
上記が入力終わると下記が表示され、Webブラウザが起動します
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: XXXX-XXXX
-
botocore-client-{SSO session name} にアクセス許可を与えるか、聞かれるので「Allow access」をクリックします
-
CLIに下記が表示されるので、適宜入力します
The only AWS account available to you is: {AWSアカウントID} Using the account ID {AWSアカウントID} The only role available to you is: {ロール} Using the role name "{ロール}" CLI default client Region [None]: ap-northeast-1 CLI default output format [None]: json CLI profile name [{ロール名}-{AWSアカウントID}]: {Profile名} To use this profile, specify the profile name using --profile, as shown: aws s3 ls --profile {Profile名} $
-
Configの内容を確認してみます
$ cat ~/.aws/config [profile XXXXX] sso_session = my-sso sso_account_id = {AWSアカウントID} sso_role_name = {ロール} region = ap-northeast-1 output = json [sso-session my-sso] sso_start_url = https://{xxxxxx}.awsapps.com/start sso_region = ap-northeast-1 sso_registration_scopes = sso:account:access $
-
試しにS3の一覧を確認します。見えました
$ aws s3 ls --profile {Profile名} XXXX XXXX $
設定後のログイン
- 下記のコマンドにより、次回からはSSOします
aws sso login --sso-session my-sso
考察
今回、brewとAWS CLIのインストールから、SSOの設定をしました。いつも忘れがちなのでメモとして残しておきます
参考