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.
Before you begin
Section titled “Before you begin”Confirm:
- AWS CLI is installed (
aws --version)- macOS (Homebrew):
brew install awscli - Linux/WSL (apt):
sudo apt update && sudo apt install awscli
- macOS (Homebrew):
- You have access to an AWS account through IAM Identity Center (ask your director or Tech Ops if you’re unsure)
Step 1: Run aws configure sso
Section titled “Step 1: Run aws configure sso”Run the interactive SSO setup (do not manually edit ~/.aws/config):
aws configure ssoThe CLI walks you through several prompts:
| Prompt | What to enter |
|---|---|
SSO session name | Any name you’d like (e.g. njoitaws) |
SSO start URL | Our org’s access portal URL (https://njoitaws.awsapps.com/start) |
SSO region | us-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:
| Prompt | What to enter |
|---|---|
CLI default client Region | us-east-1 |
CLI default output format | Press Enter to accept the default |
CLI profile name | Use the AWS account name (see naming note below) |
Step 2: Verify your config file
Section titled “Step 2: Verify your config file”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-1output = jsonsso_session = njoitawssso_account_id = 123456789012sso_role_name = AdministratorAccess
[sso-session njoitaws]sso_start_url = https://njoitaws.awsapps.com/startsso_region = us-east-1sso_registration_scopes = sso:account:accessBoth 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:
# Should print the sso_start_url; if it prints nothing, the config is wrongaws configure get sso_start_url --profile ui-devStep 3: Log in and verify
Section titled “Step 3: Log in and verify”Log in:
aws sso login --profile ui-devThis opens your browser for authentication. Once you approve, the CLI caches temporary credentials locally.
Verify:
aws sts get-caller-identity --profile ui-devYou should see your role ARN and account ID in the output.
Adding more accounts
Section titled “Adding more accounts”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-1sso_session = njoitawssso_account_id = 123456789012sso_role_name = AdministratorAccess
[profile dol-prod]region = us-east-1sso_session = njoitawssso_account_id = 987654321098sso_role_name = ReadOnlyAccess
[sso-session njoitaws]sso_start_url = https://njoitaws.awsapps.com/startsso_region = us-east-1sso_registration_scopes = sso:account:accessSwitch between accounts by passing --profile to any AWS CLI command:
aws sts get-caller-identity --profile ui-devaws sts get-caller-identity --profile dol-prodTroubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause | Fix |
|---|---|---|
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. |
ExpiredTokenException | Your SSO session expired | Run aws sso login --profile … again |
AWS_PROFILE seems ignored | Explicit access-key env vars (AWS_ACCESS_KEY_ID, etc.) are taking precedence | unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN and retry |