Sub topic 4
Configuring an sso-session and profiles
This chapter assumes you have AWS CLI version 2 installed, know what AWS accounts and IAM roles are, and have an IAM Identity Center user with at least one permission set assigned. You will see how the CLI configuration file ties a sign-in to one or more accounts.
Two kinds of blocks
The AWS CLI keeps its settings in ~/.aws/config. For IAM Identity Center, you use two kinds of blocks:
- An
sso-sessionblock describes the sign-in: which Identity Center instance to talk to and what access to request. - A
profileblock describes one destination: an account, a role (the permission set), and a default Region. A profile points to a session by name.
Separating the two means you authenticate once and use that sign-in for many accounts. Before this layout existed, each profile repeated the start URL and Region, and each needed its own sign-in.
A working configuration
This file defines one session and two profiles. The start URL and account IDs are placeholders.
[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-2Note the header syntax. Session blocks are written [sso-session name]. Profile blocks in the config file are written [profile name]. The word profile is required here, except for [default].
What each setting means
| Setting | Block | Meaning |
|---|---|---|
| `sso_start_url` | sso-session | The AWS access portal URL for your Identity Center instance |
| `sso_region` | sso-session | The Region where Identity Center is enabled |
| `sso_registration_scopes` | sso-session | The access the CLI requests. `sso:account:access` lets it list accounts and get role credentials |
| `sso_session` | profile | The name of the session block to use |
| `sso_account_id` | profile | The 12-digit account to access |
| `sso_role_name` | profile | The name of the permission set, as it appears as a role in that account |
| `region` | profile | The Region for service API calls |
Two Regions appear here, and they are unrelated. sso_region is where your Identity Center lives. region is where your commands run. A common mistake is putting the service Region in sso_region, which makes sign-in fail.
The sso_registration_scopes setting is what marks the session as the newer, token-refreshing kind. With it present, the CLI can refresh the sign-in token without sending you back to the browser until the session limit is reached.
How the pieces connect
Common mistakes
- Using
[sso-session name]as[profile name], or leaving out theprofilekeyword. The CLI then reports that the profile cannot be found. - Referring to a session name in
sso_sessionthat does not match any block. Names are case-sensitive. - Mistyping
sso_role_name. It must match a permission set that is assigned to your user in that account. If it does not, the CLI can sign you in but fails when it fetches credentials. - Mixing legacy keys (
sso_start_urlinside a profile) withsso_sessionin the same profile. Keep the sign-in settings in the session block.
You can write this file by hand, as above. The next chapter shows how aws configure sso generates it for you.
Exercise
You want a profile named staging for account 777788889999 using the permission set PowerUserAccess, reusing the my-sso session. Write the block. Which setting must you not copy into it from the session block?
Show answer
[profile staging]
ssosession = my-sso
ssoaccountid = 777788889999
ssorolename = PowerUserAccess
region = us-west-2
You must not copy `ssostarturl, ssoregion, or ssoregistrationscopes into the profile. They belong in the sso-session block, and duplicating them in the profile mixes the new and legacy formats. The region` value is your choice for service calls.