参考: 共有ファイルconfigと credentials ファイルを使用して AWS SDKs とツールをグローバルに設定する - AWS SDKsとツール
各ファイルは INI 形式で記述される。
[セクション名]
キー=値
キー=値
[別のセクション名]
キー=値configファイル
デフォルトプロファイル
[default]
region = us-east-2
output = json名前付きプロファイル
[profile dev]
region = us-west-2
output = table
[profile prod]
region = us-east-1
output = jsonSSOプロファイル
以下の例は、「my-sso」のトークンを使用して「111122223333」アカウントの「SampleRole」IAM ロールの短期 AWS 認証情報を取得するプロファイルを設定する例
「my-sso」sso-session セクションは、profile セクションの中で sso-session キーを使用して名前で参照される
[profile dev]
sso_session = my-sso
sso_account_id = 111122223333
sso_role_name = SampleRole
[sso-session my-sso]
sso_region = us-east-1
sso_start_url = https://my-sso-portal.awsapps.com/start
aws sso configureコマンド実行時の configファイルの変化
aws sso configureを実行すると、sso session name、profile名の入力を求められる% aws configure sso SSO session name (Recommended): test SSO start URL [None]: https://d-xxxxxxx.awsapps.com/start SSO region [None]: ap-northeast-1 SSO registration scopes [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://oidc.ap-northeast-1.amazonaws.com/authorize?response_type=... The only AWS account available to you is: xxxxxxxxxxx Using the account ID xxxxxxxxxxx The only role available to you is: AWSAdministratorAccess Using the role name "AWSAdministratorAccess" CLI default client Region [ap-northeast-1]: CLI default output format [json]: CLI profile name [AWSAdministratorAccess-xxxxxxxxxxx]: To use this profile, specify the profile name using --profile, as shown: aws s3 ls --profile AWSAdministratorAccess-xxxxxxxxxxxすると、以下のようにconfigファイルに2つセクションが追加される
[profile AWSAdministratorAccess-xxxxxxxxxxx] sso_session = test sso_account_id = xxxxxxxxxxx sso_role_name = AWSAdministratorAccess region = ap-northeast-1 output = json [sso-session test] sso_start_url = https://d-xxxxxxxxx.awsapps.com/start sso_region = ap-northeast-1 sso_registration_scopes = sso:account:access
credentialsファイル
credentials ファイルに配置できるのは以下のみ。
aws_access_key_idaws_secret_access_key
上記の情報はconfigファイルに配置することも可能だが、機密性の高い値はcredentialsファイルに配置することが推奨される。
また、プロファイルセクションはconfigファイルと違って[profile profile-name]とprofileから始まらない。 括弧の間にはプロファイル名のみを指定する
デフォルトプロファイル
[default]
aws_access_key_id=AKIAIOS...
aws_secret_access_key=wJal...
名前付きプロファイル(profile接頭辞なし)
[dev]
aws_access_key_id=AKIA12...
aws_secret_access_key=je7M...
[prod]
aws_access_key_id=AKIA0...
aws_secret_access_key=abc12...