It initializes the SecretsProvider class.
Optional
config: SecretsProviderOptionsThe configuration object.
Protected
_getRetrieve a configuration from AWS Secrets Manager.
Name of the configuration or its ID
Optional
options: SecretsGetOptionsSDK options to propagate to the AWS SDK v3 for JavaScript client
Protected
_getRetrieve a secret from AWS Secrets Manager.
The name of the secret
Optional
options: InferredFromOptionsType & SecretsGetOptionsOptions to customize the retrieval of the secret
import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets';
const secretsProvider = new SecretsProvider();
export const handler = async (): Promise<void> => {
// Retrieve a secret
const secret = await secretsProvider.get('my-secret');
};
You can customize the retrieval of the secret by passing options to the function:
maxAge
- The maximum age of the value in cache before fetching a new one (in seconds) (default: 5)forceFetch
- Whether to always fetch a new value from the store regardless if already available in cachetransform
- Whether to transform the value before returning it. Supported values: json
, binary
sdkOptions
- Extra options to pass to the AWS SDK v3 for JavaScript clientFor usage examples check SecretsProvider.
Intro
The Parameters utility provides a SecretsProvider that allows to retrieve secrets from AWS Secrets Manager.
Getting started
This utility supports AWS SDK v3 for JavaScript only (
@aws-sdk/client-secrets-manager
). This allows the utility to be modular, and you to install only the SDK packages you need and keep your bundle size small.Basic usage
Example
If you want to retrieve secrets without customizing the provider, you can use the getSecret function instead.
Advanced usage
Caching
By default, the provider will cache parameters retrieved in-memory for 5 seconds. You can adjust how long values should be kept in cache by using the
maxAge
parameter.Example
If instead you'd like to always ensure you fetch the latest parameter from the store regardless if already available in cache, use the
forceFetch
parameter.Example
Transformations
For parameters stored in JSON or Base64 format, you can use the transform argument for deserialization.
Example
Extra SDK options
When retrieving a secret, you can pass extra options to the AWS SDK v3 for JavaScript client by using the
sdkOptions
parameter.Example
This object accepts the same options as the AWS SDK v3 for JavaScript Secrets Manager client.
Customize AWS SDK v3 for JavaScript client
By default, the provider will create a new Secrets Manager client using the default configuration.
You can customize the client by passing a custom configuration object to the provider.
Example
This object accepts the same options as the AWS SDK v3 for JavaScript Secrets Manager client.
Otherwise, if you want to use a custom client altogether, you can pass it to the provider.
Example
This object must be an instance of the AWS SDK v3 for JavaScript Secrets Manager client.
For more usage examples, see our documentation.
See
https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parameters/