Skip to content

Instantly share code, notes, and snippets.

@aldegoeij
Last active November 26, 2024 22:26
Show Gist options
  • Save aldegoeij/e39952d280a3d04c8923e27d0dd78dac to your computer and use it in GitHub Desktop.
Save aldegoeij/e39952d280a3d04c8923e27d0dd78dac to your computer and use it in GitHub Desktop.
Using `aws sso` on the cli

Setup aws sso

Using cli wizard

Editing the aws config file

See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html#cli-configure-sso-manual

Setup SSO, add to ~/.aws/config:

[sso-session my-sso]
sso_region = us-east-1
sso_start_url = https://my-sso-portal.awsapps.com/start

Setup account access, add to ~/.aws/config:

[profile some-dev]
sso_session = my-sso
sso_account_id = 111122223333
sso_role_name = SampleRole

Using aws sso

To refresh you cli aws credentials:

aws sso login

This does not sign you in to a specific account, you need to do e.g.:

aws sso login --profile some-dev

Or, much easier, using direnv in a project that you are working on:

|- CoolProject
  |- envs
    |- dev
      |- .envrc
      |- main.tf
    |- prod
#.envrc
export AWS_PROFILE=some-dev

So if you run Terraform commands in /CoolProject/envs/dev/ the aws-cli will automatically use the AWS SSO creds for that profile (Terraform uses aws sdk under the hood, which also picks this up)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment