View a markdown version of this page

Using Amazon Credential Daemon with the Amazon CLI and Amazon SDKs - Amazon Command Line Interface
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Using Amazon Credential Daemon with the Amazon CLI and Amazon SDKs

You can use Amazon Credential Daemon today with any Amazon CLI version and any Amazon SDK that supports the credential_process setting in the shared Amazon config file. The Amazon CLI, the Amazon SDKs, and tools built on them (such as Terraform and the Amazon CDK) run a command you specify to get credentials. With Amazon Credential Daemon, that command is creds get. It returns short-lived session credentials from the daemon, and keeps long-term keys and session tokens out of ~/.aws.

How it works

When a tool needs credentials for a profile that uses credential_process, the following happens:

  1. A tool needs credentials for a profile and finds credential_process in that profile.

  2. The tool runs creds get --credential name --format credential-process.

  3. Amazon Credential Daemon returns temporary credentials as JSON: an ASIA... access key ID, a secret access key, a session token, and an expiration. The long-term secret (access key, refresh token, or private key) never leaves the daemon.

  4. The tool uses the credentials, and runs the command again before they expire.

Prerequisites

Before you configure a profile, confirm the following:

  • Amazon Credential Daemon is installed and running. To check, run credsd status. For installation instructions, see Installing Amazon Credential Daemon.

  • A credential is stored in Amazon Credential Daemon. To check, run creds list. For example, to store an IAM Identity Center sign-in, run the following command.

    $ creds bootstrap --credential work aws-idc-sso \ --start-url https://example.awsapps.com/start --sso-region us-east-1 \ --account-id 111122223333 --role-name Developer
  • You know the full path to creds. To find it, run command -v creds. A user-scoped macOS install puts it in ~/.local/bin/creds; a Linux system install puts it in /usr/local/bin/creds.

Configure a profile that gets credentials from Amazon Credential Daemon

To configure a profile that gets credentials from Amazon Credential Daemon, complete the following steps:

  1. Open the shared config file, ~/.aws/config.

  2. Add a profile whose credential_process setting runs creds get. Use the absolute path to creds, because the tool that runs the command might not use your shell's PATH.

    [profile work] region = us-east-1 credential_process = /Users/alice/.local/bin/creds get --credential work --format credential-process
  3. Remove anything for this profile that would take precedence over credential_process: aws_access_key_id and aws_secret_access_key in ~/.aws/credentials, and AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN in your environment. The Amazon CLI and SDKs use those first.

  4. Test the profile. The output shows the role session that Amazon Credential Daemon served.

    $ aws sts get-caller-identity --profile work { "UserId": "AROAEXAMPLEID:alice", "Account": "111122223333", "Arn": "arn:aws:sts::111122223333:assumed-role/Developer/alice" }

Examples

The following examples show how to use a credential_process profile with the Amazon CLI, Amazon SDKs, and other tools.

Run the command yourself

To see what a tool receives, run the command directly.

$ creds get --credential work --format credential-process {"Version":1,"AccessKeyId":"ASIAIOSFODNN7EXAMPLE","SecretAccessKey":"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY","SessionToken":"IQoJb3JpZ2luX2VjE...","Expiration":"2026-11-23T18:00:00Z"}

Use the profile with the Amazon CLI

Pass the profile with the --profile option.

$ aws s3 ls --profile work

Or set the AWS_PROFILE environment variable.

$ export AWS_PROFILE=work $ aws s3 ls

Use the profile with an Amazon SDK

Any SDK that reads the shared config file picks up the profile. The following example uses the Amazon SDK for Python (Boto3).

import boto3 session = boto3.Session(profile_name="work") print(session.client("sts").get_caller_identity()["Arn"])

Some SDKs and tools select a profile from the environment, such as the Amazon SDK for Java, the Amazon SDK for JavaScript, Terraform, and the Amazon CDK. For these, set the AWS_PROFILE environment variable.

$ export AWS_PROFILE=work $ terraform plan

Use one sign-in for several roles

An IAM Identity Center credential can serve other account and role pairs that you allowed when you stored it (--allow-role). Give each pair its own profile.

[profile work-prod-readonly] region = us-east-1 credential_process = /Users/alice/.local/bin/creds get --credential work --account 444455556666 --role ReadOnly --format credential-process

Use credentials with a tool that doesn't read the Amazon config file

Export the credentials into the current shell instead. They are short-lived and stay only in that shell's environment.

$ eval "$(creds get --credential work --format shell)"

Shell formats are also available for fish and PowerShell (--format fish, --format powershell).

Give an AI coding agent its own profile

Store a separate credential for the agent, and point the agent's profile at it. Add --agentic so that Amazon Credential Daemon records the caller as an agent in its audit trail.

[profile agent] region = us-east-1 credential_process = /Users/alice/.local/bin/creds get --credential agent-ro --agentic --format credential-process

Considerations

Keep the following in mind when you use a credential_process profile with Amazon Credential Daemon:

  • The command runs without a shell. Most SDKs split the credential_process value into arguments and run it directly. Don't use pipes, ~, or environment variables such as $HOME in the value. Use full paths.

  • Credentials refresh automatically. Tools run the command again shortly before the expiration, and Amazon Credential Daemon renews the session when it can. If a sign-in can no longer renew on its own (for example, an IAM Identity Center session that has ended), the command fails until you run creds login --credential name.

  • Errors reach the tool. If Amazon Credential Daemon can't serve credentials, creds get exits with a non-zero status and prints the reason to standard error. The Amazon CLI or SDK includes that message in its error, for example Error when retrieving credentials from custom-process: ....

  • Removing or replacing a credential needs approval. Reading a credential with creds get doesn't. Operations that remove or replace stored credentials ask for Touch ID on macOS, or sudo creds request approve id on Linux.

Troubleshooting

The following table lists common messages, their causes, and how to fix them.

Message

Cause

Fix

credential_process returned exit code 127, or No such file or directory

The tool couldn't find creds.

Use the absolute path from command -v creds.

Unable to locate credentials

The profile name is wrong, or the tool isn't reading the config file.

Check --profile or AWS_PROFILE, and AWS_CONFIG_FILE if you set it.

The caller identity isn't the role you expected.

Keys in ~/.aws/credentials or the environment take precedence.

Remove them for this profile (step 3 of the procedure).

cannot reach the daemon at socket

The daemon isn't running.

Run credsd status. If it isn't installed or running, see Installing Amazon Credential Daemon.

re-authentication required: credential 'name' requires re-authentication

The stored sign-in has ended.

Run creds login --credential name.

credential not found: name

No credential with that name is stored in the daemon.

Run creds list, and fix --credential in the profile.