Sub topic 4
Configuring an sso-session and profiles
This chapter covers the configuration that tells the AWS CLI how to reach IAM Identity Center and which account and role each profile uses. It assumes you have done the following:
- You are comfortable editing text files in a terminal.
- You have AWS CLI version 2 installed.
- You know what an AWS account and an IAM role are.
- You have an IAM Identity Center user with at least one permission set assigned in an account.
You also need two values from your Identity Center administrator or console: the AWS access portal URL (the start URL) and the Region where Identity Center is enabled.
Where the configuration lives
The CLI reads its settings from the shared config file, ~/.aws/config on Linux and macOS and %UserProfile%\.aws\config on Windows. Identity Center settings belong in this file. Do not put them in ~/.aws/credentials, which is meant for static keys and does not understand sso-session blocks.
The file is INI-style. Each section header names a kind of section:
| Header | Meaning |
|---|---|
| `[default]` | The profile used when none is selected |
| `[profile name]` | A named profile. The word `profile` is required here. |
| `[sso-session name]` | A reusable block of Identity Center sign-in settings |
The profile prefix is a frequent source of mistakes. In ~/.aws/config, a section written as [dev] is not read as a profile named dev. Only [default] is exempt from the prefix.
Two kinds of blocks, two jobs
An Identity Center setup is split into two parts.
- The
sso-sessionblock says how to sign in. It holds the portal URL, the Identity Center Region, and the scopes you ask for. Signing in produces one access token for this session. - Each
profileblock says what to use after signing in. It holds an account ID, a role name, and the Region your commands run in. It points at the session by name.
Because the sign-in settings live in one place, several profiles can share a single sign-in. You authorize once in the browser, and the same token lets the CLI fetch role credentials for every profile that references the session.
A complete example
This is the configuration from the plan. The start URL and account IDs are placeholders, so replace them with your own.
[sso-session my-sso]
sso_start_url = https://example.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access
[profile dev]
sso_session = my-sso
sso_account_id = 111122223333
sso_role_name = ReadOnlyAccess
region = us-west-2
[profile prod]
sso_session = my-sso
sso_account_id = 444455556666
sso_role_name = ReadOnlyAccess
region = us-west-2The sso-session settings
Each setting in the sso-session block has a specific purpose.
sso_start_urlis the address of your AWS access portal. It usually looks likehttps://d-xxxxxxxxxx.awsapps.com/start, or uses a custom alias if your administrator set one. Copy it exactly from the portal or console.sso_regionis the Region that hosts your Identity Center instance. The CLI calls the sign-in and token services in this Region. It does not choose where your service commands run.sso_registration_scopeslists the OAuth scopes the CLI requests when it registers itself as a client.sso:account:accessis the scope that allows listing accounts and getting role credentials. Without a scope line, the CLI cannot refresh the token automatically.
The session name, here my-sso, is only a label. It must match between the [sso-session my-sso] header and every sso_session = my-sso line. The CLI also uses the name to build the file name of its cached token (see the caching chapter), so renaming a session later means signing in again.
The profile settings
Each profile needs these settings.
sso_sessionnames thesso-sessionblock to use.sso_account_idis the 12-digit ID of the target account. Keep it as a string of digits. Leading zeros matter.sso_role_nameis the name of the permission set assigned to you in that account. You are not choosing an arbitrary IAM role. Identity Center creates a role from the permission set in each assigned account, and this name selects it. If the name does not match a permission set you hold in that account, the CLI cannot fetch credentials.regionis the default Region for service calls made with this profile. It is separate fromsso_region. You can run commands inus-west-2while Identity Center lives inus-east-1.
You may also set output (such as json, table, or text) per profile. It is optional.
The two Region settings
Confusing the two Region settings is the most common configuration mistake.
| Setting | Lives in | Controls |
|---|---|---|
| `sso_region` | `sso-session` block | Where Identity Center and the sign-in service are |
| `region` | profile | Where your `aws s3`, `aws ec2`, and other commands go |
Setting region to your Identity Center Region by default is fine if that is where you work. Setting sso_region to your workload Region is not. Sign-in will fail or hang because the portal does not exist there.
Editing by hand versus the wizard
You can write these blocks by hand, as above. The next chapter shows aws configure sso, which asks the same questions and writes the blocks for you. Writing by hand is useful when you need many profiles. You can copy a profile block and change the account ID and role name. The wizard is useful the first time, because it lists the accounts and roles you can actually use.
You can read back what the CLI sees without signing in:
aws configure get sso_session --profile dev
aws configure get sso_account_id --profile dev
aws configure list --profile devaws configure get prints the single value the CLI would use, or nothing (exit code 1) if the key is not set. aws configure list shows each setting and where it came from, such as the config file or an environment variable. This makes it a quick check for typos before you attempt a sign-in.
The legacy format
Older tutorials show the sign-in settings inside the profile, with no sso-session block:
[profile legacy-dev]
sso_start_url = https://example.awsapps.com/start
sso_region = us-east-1
sso_account_id = 111122223333
sso_role_name = ReadOnlyAccess
region = us-west-2This still works, but it is the non-refreshable configuration. The CLI cannot renew the access token in the background, so you sign in again when the token expires. Every such profile also repeats the portal settings, and each one keeps its own token. If you have legacy profiles, move the shared values into an sso-session block and replace them with sso_session = name. Running aws configure sso and choosing a session name creates the newer form.
Common configuration mistakes
These mistakes show up repeatedly in real configs.
- Missing
profileprefix. Writing[dev]instead of[profile dev]. The CLI then reports that the profile cannot be found. - Session name mismatch. The profile says
sso_session = my-ssobut the block is[sso-session mysso]. The CLI reports that the sso-session cannot be found or is not configured. - Wrong
sso_region. Using a workload Region. The browser step or token request fails. - Wrong permission set name. Using a display label or IAM role name instead of the permission set name. Credentials cannot be retrieved for that role.
- Mixing both formats in one profile. Setting
sso_sessionand alsosso_start_urlwith a different value. The CLI rejects conflicting values, so keep the portal settings in thesso-sessionblock only. - Account ID typed as a number. Dropped leading zeros turn a 12-digit ID into an 11-digit one.
What to remember
The sso-session block holds the shared sign-in settings. Each profile names that session and adds an account ID, a permission set name, and a working Region. Keep sso_region and region separate in your head. Verify the values with aws configure get and aws configure list before you sign in.
Exercise
A teammate's profile fails with "The config profile (dev) could not be found". Their file contains [dev], sso_session = my-sso, sso_account_id = 111122223333, sso_role_name = ReadOnlyAccess, region = us-west-2, and a correct [sso-session my-sso] block. What is wrong, and what does sso_region in the session block control?
Show answer
The header must be [profile dev]. In ~/.aws/config, only [default] can omit the profile prefix. sso_region controls the Region where Identity Center and its sign-in service run. It does not set the Region for service commands such as aws s3 ls. The profile's region setting does that.
Exercise
You want to add a third account, 555566667777, with the permission set PowerUserAccess, using the same sign-in as dev and prod. Write the new profile block and say how many browser sign-ins it needs.
Show answer
Add this block:
[profile staging]
ssosession = my-sso
ssoaccountid = 555566667777
ssorole_name = PowerUserAccess
region = us-west-2
No new sso-session block and no extra sign-in is needed, because the profile references the existing my-sso session. The existing access token is reused. This assumes your Identity Center user has PowerUserAccess assigned in that account.