Sub topic 13
Exporting credentials for tools without SSO support
This chapter assumes you have a working sso-session and profile, can run aws sso login, and know how the CLI resolves credentials. Some tools do not understand IAM Identity Center profiles. Older SDKs, Terraform setups, and scripts that read only environment variables are common examples. The CLI can hand them the same temporary credentials it already holds.
Why export at all
The CLI knows how to turn a cached SSO access token into role credentials. A tool without SSO support cannot do that exchange. aws configure export-credentials performs the exchange for it and prints the result in a format the tool can consume.
The command does not create a new identity. It returns the role credentials for the profile you name, so they carry the same permissions and the same expiry as the profile's own credentials.
Export as environment variables
Sign in first, then evaluate the exported variables in your current shell:
aws sso login --profile dev
eval "$(aws configure export-credentials --profile dev --format env)"
aws sts get-caller-identityThe env format prints export lines for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN. It also prints AWS_CREDENTIAL_EXPIRATION. The last command should report the assumed-role ARN for the dev profile.
The variables sit in the environment of that shell and its child processes. They do not refresh. When they expire, calls fail until you run the export again.
Use credential_process
Environment variables are a snapshot. If a tool can read a shared config file but does not support SSO, use credential_process. The tool then calls the CLI each time it needs credentials.
[profile dev-process]
credential_process = aws configure export-credentials --profile dev --format processThe process format prints a JSON document with the credentials and their expiration time. The SDK or tool runs the command, reads the JSON, and calls it again when the credentials near expiry. This avoids stale values in the environment.
Choosing between the two
| Approach | How it gets credentials | Refreshes itself | Typical use |
|---|---|---|---|
| `--format env` with `eval` | One-time export into the shell | No | Quick scripts, one-off tools |
| `credential_process` | Tool calls the CLI on demand | Yes, while the SSO token is valid | Long-running tools, SDKs reading shared config |
Common mistakes
- Exporting before signing in. The command fails with an error about a missing or expired token. Run
aws sso loginfirst. - Forgetting that variables override profiles. Once the environment variables are set, they take precedence over
AWS_PROFILEin the credential chain. Later commands keep using the exported credentials, even if you switch profiles. Unset the four variables, or open a new shell, to go back. - Leaving credentials in files. Do not paste exported values into a file or commit them to source control. They are temporary, but they are valid until they expire.
- Wrong profile name. The
--profilevalue must name the SSO profile (dev), not thecredential_processprofile that calls it. Pointing the process profile at itself creates a loop.
Clearing exported variables
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_CREDENTIAL_EXPIRATIONRunning aws sso logout removes the cached token and the CLI's cached credentials. It does not change variables you already exported, so unset them as well.
Exercise
You exported credentials with eval "$(aws configure export-credentials --profile dev --format env)". An hour later, a script in the same shell fails with an expired-token error, although aws sso login was run earlier that day. What do you do, and what could you change to avoid repeating it?
Show answer
The exported variables are a snapshot and do not refresh. Run the export command again, after aws sso login --profile dev if the SSO token has also expired. To avoid repeating this, configure a credential_process profile that calls aws configure export-credentials --profile dev --format process, so the tool requests fresh credentials each time it needs them.
Exercise
After exporting dev credentials, you set AWS_PROFILE=prod and run aws sts get-caller-identity. Which account does it report, and why?
Show answer
It reports the dev account. Environment credentials come before profile-based credentials in the resolution order, so the exported variables win over AWS_PROFILE. Unset the exported variables to use prod.