

# 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`.

**Topics**
+ [How it works](#getting-started-credsd-credential-process-how)
+ [Prerequisites](#getting-started-credsd-credential-process-prereqs)
+ [Configure a profile that gets credentials from Amazon Credential Daemon](#getting-started-credsd-credential-process-configure)
+ [Examples](#getting-started-credsd-credential-process-examples)
+ [Considerations](#getting-started-credsd-credential-process-considerations)
+ [Troubleshooting](#getting-started-credsd-credential-process-troubleshooting)

## How it works
<a name="getting-started-credsd-credential-process-how"></a>

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.

1. The tool runs `creds get --credential {{name}} --format credential-process`.

1. 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.

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

## Prerequisites
<a name="getting-started-credsd-credential-process-prereqs"></a>

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](getting-started-credsd-install.md).
+ 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
<a name="getting-started-credsd-credential-process-configure"></a>

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

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

1. 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
   ```

1. 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.

1. 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
<a name="getting-started-credsd-credential-process-examples"></a>

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

### Run the command yourself
<a name="getting-started-credsd-credential-process-example-run"></a>

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
<a name="getting-started-credsd-credential-process-example-cli"></a>

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
<a name="getting-started-credsd-credential-process-example-sdk"></a>

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
<a name="getting-started-credsd-credential-process-example-multi-role"></a>

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
<a name="getting-started-credsd-credential-process-example-no-config"></a>

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
<a name="getting-started-credsd-credential-process-example-agent"></a>

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
<a name="getting-started-credsd-credential-process-considerations"></a>

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
<a name="getting-started-credsd-credential-process-troubleshooting"></a>

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](getting-started-credsd-install.md). | 
| `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. | 