Skip to content

Set up AWS CLI with SSO

This guide walks you through setting up AWS CLI SSO profiles using IAM Identity Center (formerly AWS SSO). Once configured, these profiles can be used by any tool that reads AWS credentials: Claude Code, Terraform, the AWS CLI itself, etc.

Confirm:

  • AWS CLI is installed (aws --version)
    • macOS (Homebrew): brew install awscli
    • Linux/WSL (apt): sudo apt update && sudo apt install awscli
  • You have access to an AWS account through IAM Identity Center (ask your director or Tech Ops if you’re unsure)

Run the interactive SSO setup (do not manually edit ~/.aws/config):

Terminal window
aws configure sso

The CLI walks you through several prompts:

PromptWhat to enter
SSO session nameAny name you’d like (e.g. njoitaws)
SSO start URLOur org’s access portal URL (https://njoitaws.awsapps.com/start)
SSO regionus-east-1
SSO registration scopes [sso:account:access]Press Enter to accept the default

After browser-based login, the CLI lists available AWS accounts. Select your project-specific account. Then pick the role you want to use (if you have access to multiple roles; otherwise, it’ll choose for you).

Finally, set local profile defaults:

PromptWhat to enter
CLI default client Regionus-east-1
CLI default output formatPress Enter to accept the default
CLI profile nameUse the AWS account name (see naming note below)

Open ~/.aws/config and confirm it contains both a profile block and a matching sso-session block. The example below uses the profile name ui-dev; yours will match the name you chose in the previous step:

[profile ui-dev]
region = us-east-1
output = json
sso_session = njoitaws
sso_account_id = 123456789012
sso_role_name = AdministratorAccess
[sso-session njoitaws]
sso_start_url = https://njoitaws.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access

Both blocks are required. The profile block references the session by name (sso_session = njoitaws), and the [sso-session njoitaws] block contains the actual SSO endpoint details. If either block is missing or the names don’t match, aws sso login will fail.

You can also verify programmatically:

Terminal window
# Should print the sso_start_url; if it prints nothing, the config is wrong
aws configure get sso_start_url --profile ui-dev

Log in:

Terminal window
aws sso login --profile ui-dev

This opens your browser for authentication. Once you approve, the CLI caches temporary credentials locally.

Verify:

Terminal window
aws sts get-caller-identity --profile ui-dev

You should see your role ARN and account ID in the output.


If you have access to multiple AWS accounts, run aws configure sso once for each account. Each run creates a new [profile ...] block in ~/.aws/config, but they all share the same [sso-session njoitaws] block. You only need to authenticate through the browser once per session.

For example, after setting up two accounts your config might look like:

[profile ui-dev]
region = us-east-1
sso_session = njoitaws
sso_account_id = 123456789012
sso_role_name = AdministratorAccess
[profile dol-prod]
region = us-east-1
sso_session = njoitaws
sso_account_id = 987654321098
sso_role_name = ReadOnlyAccess
[sso-session njoitaws]
sso_start_url = https://njoitaws.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access

Switch between accounts by passing --profile to any AWS CLI command:

Terminal window
aws sts get-caller-identity --profile ui-dev
aws sts get-caller-identity --profile dol-prod

SymptomLikely causeFix
Missing the following required SSO configuration values: sso_start_url, sso_region~/.aws/config is missing the [sso-session ...] block, or the profile’s sso_session name doesn’t match. Common when config was hand-edited instead of generated by aws configure sso.Run aws configure sso to regenerate both blocks. See Step 2 for the required two-block structure.
ExpiredTokenExceptionYour SSO session expiredRun aws sso login --profile … again
AWS_PROFILE seems ignoredExplicit access-key env vars (AWS_ACCESS_KEY_ID, etc.) are taking precedenceunset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN and retry