Sub topic 5
Letting aws configure sso write the configuration
This chapter assumes you have AWS CLI version 2 installed, a working knowledge of AWS accounts and IAM roles, and an IAM Identity Center user with at least one assigned permission set. The previous chapter showed how to write an sso-session block and profiles by hand. Here you let the CLI do that work and learn to check what it wrote.
What the wizard does
aws configure sso is an interactive command. It asks a few questions, opens your browser so you can authorize the CLI, lists the accounts and roles you can use, and then writes the result to ~/.aws/config. You end up with the same [sso-session] and [profile] blocks you would otherwise type yourself.
The wizard saves you from two common mistakes: mistyping the start URL and guessing account IDs or role names. It reads the accounts and roles from Identity Center, so the values it writes are ones you are actually assigned.
aws configure sso
# Prompts for a session name, start URL, SSO region and registration scopes,
# opens a browser to authorize, then asks you to pick an account, a role,
# a default region and a profile name.The prompts in order
The wizard asks for these values in sequence. Have them ready before you start.
| Prompt | What to enter | Where it ends up |
|---|---|---|
| SSO session name | A label you choose, such as `my-sso` | The name in `[sso-session my-sso]` |
| SSO start URL | The AWS access portal URL for your Identity Center instance | `sso_start_url` |
| SSO region | The Region where Identity Center is enabled | `sso_region` |
| SSO registration scopes | Usually `sso:account:access` | `sso_registration_scopes` |
| Account | Chosen from a list after you authorize in the browser | `sso_account_id` |
| Role | Chosen from the permission sets assigned to you in that account | `sso_role_name` |
| Default client Region | The Region your commands target when none is given | `region` |
| Default output format | `json`, `yaml`, `text`, `table` or none | `output` |
| Profile name | The name you will pass to `--profile` | The name in `[profile name]` |
The SSO region is where Identity Center lives. It is often different from the default client Region, which is where your resources live. Do not enter one value for both unless they really are the same.
The start URL usually looks like https://example.awsapps.com/start. Your administrator can give it to you, or you can find it on the Identity Center settings page. If your organization set a custom domain, use that URL instead.
The browser authorization step
After you enter the scopes, the CLI starts a sign-in. It tries to open your default browser. If it cannot, for example over an SSH connection, it prints a URL and a short code instead. Open the URL on any device, sign in, check that the code matches, and approve the request.
This step does two things. It proves you are the user, and it gives the CLI an access token for the session. The wizard needs that token to ask Identity Center which accounts and roles you can use. The token is cached on disk, so the aws sso login command in a later chapter can reuse the same session.
If your terminal has no browser, you can ask for the device-code flow explicitly:
aws configure sso --no-browserThe CLI then prints the URL and code and waits while you approve on another device.
What gets written
Suppose you answer the prompts with session name my-sso, account 111122223333, role ReadOnlyAccess, Region us-west-2, and profile name dev. The wizard produces a configuration like this:
[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-2Both blocks matter. The profile holds the account and role. It points at the session by name through sso_session. The session holds the start URL, the SSO Region and the scopes. Because the session is a separate block, many profiles can share it.
Check the result by opening ~/.aws/config in an editor, or print it:
cat ~/.aws/configOn Windows the file is %UserProfile%\.aws\config.
If you left output blank
If you accept the default output format, the wizard may omit the output line. That is fine. The CLI falls back to json.
Adding a second profile on the same session
Run the wizard again for each additional account or role. When it asks for the session name, enter the name you used before, my-sso. The CLI recognizes the existing session and offers to reuse its start URL and Region. You only choose a new account, role and profile name.
The result is the layout from the chapter on configuration: two profiles that share one sso-session block, so one sign-in covers both.
[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-2If you type a different session name by mistake, the wizard creates a second sso-session block. Each session needs its own sign-in. Profiles that should sign in together must name the same session.
Checking that it worked
The wizard prints a reminder at the end that shows how to use the new profile. Test it right away:
aws sts get-caller-identity --profile devA successful call returns the account ID and an assumed-role ARN. If the call fails, the next chapters cover sign-in and troubleshooting. For now, confirm the file contents match what you entered.
Edge cases and common mistakes
- Wrong SSO region. If you enter the Region where your resources live instead of the Region where Identity Center is enabled, the browser step fails or the account list stays empty. Ask your administrator, or check the Identity Center console for the Region shown there.
- Empty account or role list. The wizard only lists accounts and permission sets assigned to your user. If the list is empty, the problem is in Identity Center, not in the CLI. An administrator has to create an assignment.
- Only one role. If you have exactly one role in the account, the wizard selects it for you and does not ask.
- Re-running for an existing profile name. If you enter a profile name that already exists, the wizard overwrites that profile's values. Use a new name unless you mean to replace it.
- Legacy configuration. Older CLI documentation shows profiles with
sso_start_urlandsso_regioninside the profile and nosso-sessionblock. That form still works, but it does not support the token refresh behavior covered later. Prefer thesso-sessionform the wizard writes today. - Scopes left blank. Without
sso:account:access, the CLI cannot list accounts and roles. Keep the default unless you have a specific reason to change it. - Hand editing afterward. The file is plain text, so you can edit it. Keep the section headers exact:
[sso-session name]with a space, and[profile name]. A typo insso_sessionthat does not match any block causes errors when you sign in.
Wizard or hand editing
Use the wizard when you are setting up a new machine, adding an account, or unsure of an account ID or role name. Edit the file by hand when you roll out the same configuration to many machines, for example through a template or a dotfiles repository. The wizard gives you correct values. Hand editing gives you repeatability. Many teams run the wizard once, then copy the resulting blocks into shared documentation.
Exercise
You ran aws configure sso once and created the profile dev. Now you need a profile prod for another account, and you want one browser sign-in to cover both. What session name do you enter at the first prompt, and what happens if you enter a new name instead?
Show answer
Enter the same session name you used for dev, such as my-sso. The CLI then reuses the existing sso-session block and writes only a new profile that points to it with sso_session. If you enter a new name, the wizard creates a second sso-session block, and prod needs its own sign-in separate from dev.
Exercise
After running the wizard, the account list is empty. Is the cause in the AWS CLI configuration or in Identity Center, and who can fix it?
Show answer
The cause is in Identity Center. The wizard lists only the accounts and permission sets assigned to your user. An Identity Center administrator must create an account assignment for you, and then you can run the wizard again.