

# Use an API key with Credential Broker

**Note**  
This is prerelease documentation for a service in preview release. It is subject to change.

Use an API key provider when the external service accepts only a static API key and does not support OAuth. Your workload calls `GetApiKey` with its own AWS IAM credentials, and an IAM policy controls which workloads can retrieve the key. Credential Broker holds the key centrally instead of leaving it in your workload's configuration.

A credential provider holds one type of credential, either OAuth or an API key, and its type is fixed when you create the provider. An API key provider holds one API key.

## Key characteristics
<a name="credential-broker-api-keys-characteristics"></a>

An API key provider has the following characteristics:
+ The external service accepts a static API key rather than OAuth
+ There is no end user, no consent prompt, and no token exchange
+ The provider holds one API key, and its type is fixed when you create it
+ Your workload retrieves the key with `GetApiKey` using its own AWS IAM credentials

## Example scenario
<a name="credential-broker-api-keys-scenario"></a>

An application that runs on Lambda calls an external service that authenticates with a static API key. There is no end user; the application calls the service as itself.

1. **Priya (identity admin)** creates a credential provider pool and an API key provider that holds the key for the external service, and grants the application's role permission to call the broker.

1. **Diego (application developer)** calls the broker from the application with the provider ARN. He stores no API key in the application's configuration. Credential Broker returns the API key, which the application uses to call the external service.

## How it works
<a name="credential-broker-api-keys-how"></a>

At runtime, your workload retrieves the API key in a single call.

**To retrieve an API key**

1. Call `GetApiKey` with the provider ARN. The response returns the API key.

1. Use the API key to call the external service.

The following example retrieves an API key with the AWS CLI.

```bash
aws credential-broker get-api-key \
  --region us-east-1 \
  --credential-provider-arn <providerArn>
```

## Set up
<a name="credential-broker-api-keys-setup"></a>

To set up an API key provider, create a credential provider in your credential provider pool and enter the API key.

**To create an API key provider**

1. In the credential provider pool, create a credential provider.

1. For **Credential type**, choose **API key**.

1. For **API key source**, choose **Enter a new API key**, and then enter the API key value. Credential Broker stores the key in a managed AWS Secrets Manager secret.

(Optional) For **API key source**, you can instead choose an existing AWS Secrets Manager secret that contains your API key. When you do, you control that secret's encryption, rotation, tags, and other settings.

For a worked example that configures a credential provider and retrieves a credential, see [Getting started: Set up your first credential provider](credential-broker-setup.md).

## Permissions
<a name="credential-broker-api-keys-permissions"></a>

The caller needs the `credentialbroker:GetApiKey` action on the API key provider's ARN. For an example policy for this flow, see [Control access to AWS IAM Credential Broker](credential-broker-permissions.md).

## Related resources
<a name="credential-broker-api-keys-related"></a>
+ [Credential Broker API Reference](https://docs.aws.amazon.com/credentialbroker/latest/APIReference/)
+ [AWS CLI commands for Credential Broker](https://docs.aws.amazon.com/cli/latest/reference/credentialbroker/)