Configuring IAM Identity Center (AWS SSO) authentication with the AWS CLI - A comprehensive guide covering setup, configuration, security best practices, and troubleshooting

AWS SSO provides centralized access to multiple AWS accounts using identity federation. This guide explains how to configure the AWS CLI to authenticate with AWS SSO.

Prerequisites

  1. AWS CLI v2 installed (aws --version)
  2. Access to your AWS SSO portal (provided by your AWS administrator)
  3. Your SSO Start URL and SSO Region
  4. AWS Account IDs you need to access
  5. IAM Role names assigned to your user

Understanding AWS SSO Configuration

AWS SSO uses two configuration sections in ~/.aws/config:

The AWS CLI stores temporary credentials in ~/.aws/sso/cache/. These credentials expire after 8-12 hours.

Setup Process

Using the AWS CLI Wizard

Run the configuration wizard:

aws configure sso

The wizard asks for:

Complete the wizard for each account and role combination you need.

Manual Configuration

Edit ~/.aws/config directly. Add sections for each profile and SSO session:

[profile Default]
sso_session = default-sso
sso_account_id = 111122223333
sso_role_name = Administrator
region = ap-southeast-2
output = json

[profile Company-1-ReadOnly]
sso_session = company-1-sso
sso_account_id = 222233334444
sso_role_name = ReadOnly
region = ap-southeast-2
output = json

[profile Company-1-Administrator]
sso_session = company-1-sso
sso_account_id = 222233334444
sso_role_name = Administrator
region = ap-southeast-2
output = json

[profile Company-2-ReadOnly]
sso_session = company-2-sso
sso_account_id = 333344445555
sso_role_name = ReadOnly
region = ap-southeast-2
output = json

[profile Company-2-Administrator]
sso_session = company-2-sso
sso_account_id = 333344445555
sso_role_name = Administrator
region = ap-southeast-2
output = json

[sso-session default-sso]
sso_start_url = https://d-1234567890.awsapps.com/start
sso_region = ap-southeast-2
sso_registration_scopes = sso:account:access

[sso-session company-1-sso]
sso_start_url = https://d-9876543210.awsapps.com/start
sso_region = ap-southeast-2
sso_registration_scopes = sso:account:access

[sso-session company-2-sso]
sso_start_url = https://d-555666777.awsapps.com/start
sso_region = ap-southeast-2
sso_registration_scopes = sso:account:access

Each AWS organization requires its own SSO session. Profiles within the same organization can share an SSO session. In this example, Company-1-ReadOnly and Company-1-Administrator share the same SSO session, as do Company-2-ReadOnly and Company-2-Administrator.

Daily Usage

Login

Authenticate with AWS SSO:

# Login to a specific profile
aws sso login --profile Default

# Login to all profiles sharing an SSO session
aws sso login --sso-session company-1-sso
aws sso login --sso-session company-2-sso

The first login opens your browser for authentication. Complete the login process in your browser.

Using Profiles

Specify a profile for individual commands:

aws s3 ls --profile Company-1-ReadOnly
aws ec2 describe-instances --profile Company-1-Administrator
aws s3 cp file.txt s3://bucket --profile Company-2-ReadOnly

Set a default profile for your session:

export AWS_PROFILE=Company-1-ReadOnly
aws s3 ls  # Uses Company-1-ReadOnly profile

Verify Authentication

Check your current identity:

aws sts get-caller-identity --profile Company-1-ReadOnly

Logout

Clear cached credentials:

# Logout specific profile
aws sso logout --profile Company-1-ReadOnly

# Logout all SSO sessions
aws sso logout

Security Considerations

Security Best Practices

Token Management

Permission Management

Configuration Security

Network Security

Credential Hygiene

Troubleshooting

Session Expired

Error: "The SSO session associated with this profile has expired"

Solution:

aws sso login --profile Company-1-ReadOnly

Corrupted Token Cache

Error: "Invalid grant provided"

Solution:

rm -rf ~/.aws/sso/cache/
aws sso login --profile Company-1-ReadOnly

Profile Not Found

Error: "Profile Company-1-ReadOnly not found"

Solution: Verify the profile name exists in ~/.aws/config

Configuration Reference

Profile Section

[profile PROFILE_NAME]
sso_session = SESSION_NAME          # References [sso-session] section
sso_account_id = 123456789012       # 12-digit AWS Account ID
sso_role_name = RoleName            # IAM Role name in AWS SSO
region = ap-southeast-2             # Default region for AWS commands
output = json                       # Output format (json, text, table)

SSO Session Section

[sso-session SESSION_NAME]
sso_start_url = https://d-xxxxx.awsapps.com/start   # SSO portal URL
sso_region = ap-southeast-2                         # Region where SSO is configured
sso_registration_scopes = sso:account:access        # Required scope

Common Role Names

Standard AWS managed roles include: