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
