LoginSignup
0
0

AWS CLI + SSOのセットアップメモ

Last updated at Posted at 2024-04-21

背景・目的

AWS CLIやSSO周りの設定について忘れぽいので、メモします。

実践

前提

  • Macを利用しています

brew のインストール

  1. 下記のコマンドを実行し、インストールします

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. 途中で下記が求められるのでEnter

    Press RETURN/ENTER to continue or any other key to abort:
    
  3. 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のインストール

  1. 下記のコマンドを実行し、aws cliをインストールします
    $ brew install awscli
    
  2. 3分程度でインストールが完了します
  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の設定

  1. 下記のコマンドを実行すると、SSO session nameが求められます

    $ aws configure sso
    SSO session name (Recommended):my-sso
    
  2. 次に、SSOポータルを求められますので、指定します

    SSO start URL [None]: https://xxxxxx.awsapps.com/start
    
  3. 次にリージョンが求められますので、指定します

    SSO region [None]: ap-northeast-1
    
  4. 最後に、スコープが求められます

    SSO registration scopes [sso:account:access]: sso:account:access
    
  5. 上記が入力終わると下記が表示され、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
    
    
  6. 「Confirm and continue」をクリックします

  7. botocore-client-{SSO session name} にアクセス許可を与えるか、聞かれるので「Allow access」をクリックします

  8. Request approvedが表示されました

  9. 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名}
    $
    
  10. 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
    $
    
  11. 試しにS3の一覧を確認します。見えました

    $ aws s3 ls  --profile {Profile名}
    XXXX XXXX
    $
    

設定後のログイン

  1. 下記のコマンドにより、次回からはSSOします
    aws sso login --sso-session my-sso
    

考察

今回、brewとAWS CLIのインストールから、SSOの設定をしました。いつも忘れがちなのでメモとして残しておきます

参考

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