AwsSecretsManagerApiKeyProvider

org.llm4s.llmconnect.auth.aws.AwsSecretsManagerApiKeyProvider
See theAwsSecretsManagerApiKeyProvider companion object
@Experimental

An ApiKeyProvider that reads the API key from AWS Secrets Manager (#2479) with its GetSecretValue action, for a deployment that cannot run the Secrets Store CSI driver or External Secrets Operator to write the key to a file (apiKeyFile).

The key is read on the first current(), then reused for AwsSecretsManagerSettings.refreshInterval, then read again, so a key rotated in Secrets Manager is sent from the first request after the interval. Concurrent callers share one read. A read that fails is a Left and is tried again on the next call; the last key is not served after its interval, since a rotated-out key may already be revoked.

for
 keys   <- AwsSecretsManagerApiKeyProvider(
             AwsSecretsManagerSettings("eu-west-1", AwsCredentials(accessKeyId, Secret(secretAccessKey)), "llm4s/openai")
               .withField("apiKey")
           )
 config <- Llm4sConfig.provider("openai-main").map(_.withApiKeyProvider(keys))
 client <- LLMConnect.getClient(config)
yield client

Errors never hold the key or a credential: an AuthenticationError when AWS refuses the credentials or denies access, a NotFoundError when there is no such secret or version stage, a ConfigurationError when the secret has no usable string (binary only, a missing or blank field, more than one line), a ServiceError for any other answer, and the HTTP client's own error when Secrets Manager cannot be reached.

It depends on no AWS SDK: one POST with llm4s's own HTTP client, signed with Signature Version 4. Getting the credentials - from an instance profile, IRSA or an assumed role - stays the caller's job. Close the provider to close the HTTP client it created; one passed to AwsSecretsManagerApiKeyProvider(settings, httpClient) stays the caller's to close.

Attributes

Companion
object
Source
AwsSecretsManagerApiKeyProvider.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def close(): Unit

Closes the HTTP client this provider created; one the caller passed in is left open.

Closes the HTTP client this provider created; one the caller passed in is left open.

Attributes

Definition Classes
Source
AwsSecretsManagerApiKeyProvider.scala
override def current(): Result[ApiKey]

The key to send with the next request.

The key to send with the next request.

Attributes

Definition Classes
Source
AwsSecretsManagerApiKeyProvider.scala
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
Source
AwsSecretsManagerApiKeyProvider.scala