Sub topic 13
Exporting credentials for tools without SSO support
This chapter assumes you can already sign in with aws sso login, that your ~/.aws/config has an sso-session block and at least one profile, and that aws sts get-caller-identity --profile dev works. It also assumes you know what an environment variable is and which AWS CLI version 2 you have installed. The command in this chapter needs a reasonably recent version 2 release, so run aws --version first.
The problem: not every tool understands Identity Center profiles
The AWS CLI and current SDKs know how to read an sso_session profile. They find the cached sign-in token, ask IAM Identity Center for role credentials, and refresh them when they expire. Many other programs cannot do this. Examples include older SDK versions, third-party tools that embed their own AWS client, Docker containers, and scripts in languages with a minimal AWS library.
Almost all of these tools can read the standard credential environment variables or call an external program. The CLI offers a bridge for both cases: aws configure export-credentials. It resolves the profile the way the CLI normally would, then prints the resulting temporary credentials in a format other tools accept.
What the command does
aws configure export-credentials does not create new credentials. It reads the cached sign-in token for the profile and fetches the role credentials from Identity Center, or reuses cached ones that are still valid. It then prints them. It follows the same resolution path as any other CLI command, so it also works for profiles that assume roles.
If the cached token has expired, the command fails and you must sign in again with aws sso login --profile dev. It does not open a browser by itself.
The --format option controls the output:
| Format | Output | Typical use |
|---|---|---|
| `process` (default) | JSON in the `credential_process` schema | Tools that run a command and parse JSON |
| `env` | `export NAME=value` lines | `eval` in bash or zsh |
| `env-no-export` | `NAME=value` lines | Docker `--env-file`, `.env` files |
| `powershell` | `$Env:NAME='value'` lines | PowerShell |
| `windows-cmd` | `set NAME=value` lines | Windows Command Prompt |
Exporting to environment variables
Sign in, then export the credentials into the current shell:
aws sso login --profile dev
eval "$(aws configure export-credentials --profile dev --format env)"
aws sts get-caller-identityThe env format sets AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN. It also sets AWS_CREDENTIAL_EXPIRATION, which records when the credentials stop working. The access key ID of role credentials starts with ASIA, which tells you they are temporary. The session token is required. A tool that reads only the key ID and secret will fail with an invalid-token error, because temporary credentials are rejected without the matching token.
Check that the variables are present, without printing the secret:
echo "$AWS_ACCESS_KEY_ID"
echo "$AWS_CREDENTIAL_EXPIRATION"Gotchas with exported variables
- They are a snapshot. Nothing refreshes them. When the role credentials expire, every tool that uses the variables starts failing, and you must sign in if needed and run the export again.
- They shadow your profile. The credential variables take precedence over profile settings in the config file, so after the export, commands that use only
AWS_PROFILEcan silently use the exported credentials instead of that profile. An explicit--profileon the command line overrides them. Remove the variables when you are done with them, for example withunset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_CREDENTIAL_EXPIRATION. - They stay in the shell.
evalaffects only the current shell session and the child processes it starts. A new terminal tab has nothing exported. - Region is not included. Set
AWS_REGIONorAWS_DEFAULT_REGIONyourself, or pass the region to the tool.
Passing credentials to a container
A container does not see your ~/.aws directory unless you mount it, and even then an old SDK inside it may not understand SSO. Passing the exported variables is simpler. The env-no-export format produces lines that Docker accepts directly:
aws configure export-credentials --profile dev --format env-no-export > dev.env
docker run --rm --env-file dev.env amazon/aws-cli sts get-caller-identity
rm dev.envThis writes secrets to a file, so delete it right after use and never commit it. Even though the credentials are temporary, they are valid until they expire. Keep the file out of version control, for example with an entry in .gitignore. Where possible, pass the variables through your shell instead of writing a file.
Using credential_process for tools that can run a command
If a tool reads the shared config file but has no SSO support, you can define a second profile that calls the CLI for the credentials:
[profile dev-process]
credential_process = aws configure export-credentials --profile dev --format processWhen a tool uses dev-process, its SDK runs the command, parses the JSON from standard output, and uses the credentials. The JSON has this shape:
{
"Version": 1,
"AccessKeyId": "ASIAEXAMPLE",
"SecretAccessKey": "example-secret",
"SessionToken": "example-token",
"Expiration": "2026-11-26T19:12:30+00:00"
}Because the output includes Expiration, an SDK that supports credential_process runs the command again when the credentials are about to expire. This is a real advantage over exported variables: the long-running tool keeps working until the underlying sign-in token expires.
Points to watch:
- The profile named after
--profilemust be the SSO profile (dev), not thecredential_processprofile itself. Pointing it at itself creates a loop. - The tool must be able to find the
awsexecutable on itsPATH. Use the full path to the executable if it runs under a service account or an IDE with a reduced environment. - The command cannot prompt you. If the SSO token is gone, the command fails and the tool reports a credential error. Run
aws sso login --profile devin a terminal and retry. - Anything the command prints to standard output other than the JSON breaks parsing.
How the pieces fit together
The sequence diagram shows where each party gets its credentials. The exported credentials come from the same cache the CLI uses.
Choosing between the two approaches
| Question | Environment variables | `credential_process` |
|---|---|---|
| Refreshes automatically | No | Yes, if the SDK supports it |
| Works in a container | Yes, by passing variables | Only if the CLI and config are inside the container |
| Needs a config file change | No | Yes |
| Risk of leftover credentials | Higher, since they stay in the shell or a file | Lower, since credentials exist only in the tool's memory |
| Good for | One-off commands, containers, quick tests | Long-running local tools and IDEs |
Security considerations
Exported credentials carry the full permissions of the permission set for their remaining lifetime. They are less dangerous than long-term keys because they expire, but they can still be copied from shell history, process listings, logs, or a forgotten .env file. A few habits reduce the risk:
- Avoid pasting the credentials into a command line, because they can appear in process listings and history.
- Never print them in CI logs or share them in chat.
- Run
aws sso logoutwhen you finish. That removes the cached token and credentials, but it does not invalidate values you already exported. Those keep working until they expire.
Troubleshooting export problems
- The command reports that the token is expired or missing. Run
aws sso login --profile dev, then export again. - A tool reports "The security token included in the request is invalid". The tool probably ignored
AWS_SESSION_TOKEN, or the credentials expired. CheckAWS_CREDENTIAL_EXPIRATIONand the tool's documentation. - Commands use the wrong account after an export. Exported variables are overriding the profile. Run
aws sts get-caller-identityto see the real identity, then unset the variables. - A tool using
credential_processcannot findaws. Use an absolute path in thecredential_processline.
Exercise
You exported dev credentials with eval "$(aws configure export-credentials --profile dev --format env)" and left the terminal open. Two hours later, aws s3 ls fails with an expired-token error, even though you signed in this morning. Why does it fail, and what is the fix?
Show answer
The exported variables are a snapshot of the role credentials, and they expired at the time shown in AWSCREDENTIALEXPIRATION. Nothing refreshes them, and because they take precedence over the profile configuration, the CLI keeps using the stale values. Run aws sso login --profile dev if the SSO token has also expired, then run the export again. Alternatively, unset the variables so the CLI uses the dev profile directly, which refreshes credentials on its own.
Exercise
A desktop tool can read profiles from ~/.aws/config but does not support sso_session. It must keep working through a full workday without you re-exporting anything. Which approach fits, and what limit remains?
Show answer
Add a profile with credential_process = aws configure export-credentials --profile dev --format process and point the tool at it. The tool runs the command again when the credentials near their Expiration. The limit is the SSO sign-in session itself: when the cached token expires, the command fails and you must run aws sso login --profile dev.