It initializes the DynamoDBProvider class.
The configuration object.
Protected
keyProtected
sortProtected
storeProtected
tableProtected
valueProtected
_getRetrieve an item from Amazon DynamoDB.
Key of the item to retrieve (i.e. the partition key)
Optional
options: DynamoDBGetOptionsOptions to customize the retrieval
Protected
_getRetrieve multiple items from Amazon DynamoDB.
The path of the values to retrieve (i.e. the partition key)
Optional
options: DynamoDBGetMultipleOptionsOptions to customize the retrieval
Retrieve a value from Amazon DynamoDB.
The name of the value to retrieve (i.e. the partition key)
Optional
options: InferredFromOptionsType & DynamoDBGetOptionsOptions to configure the provider
import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb';
const tableProvider = new DynamoDBProvider({
tableName: 'my-table',
});
export const handler = async (): Promise<void> => {
// Retrieve a single value
const value = await tableProvider.get('my-value-key');
};
You can customize the retrieval of the value 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 DynamoDBProvider.
Retrieve multiple values from Amazon DynamoDB.
The path of the values to retrieve (i.e. the partition key)
Optional
options: InferredFromOptionsType & DynamoDBGetMultipleOptionsOptions to configure the provider
import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb';
const tableProvider = new DynamoDBProvider({
tableName: 'my-table',
});
export const handler = async (): Promise<void> => {
// Retrieve multiple values
const values = await tableProvider.getMultiple('my-values-path');
};
You can customize the retrieval of the values 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 clientthrowOnTransformError
- Whether to throw an error if the transform fails (default: true
)For usage examples check DynamoDBProvider.
Intro
The Parameters utility provides a DynamoDBProvider that allows to retrieve values from Amazon DynamoDB.
Getting started
This utility supports AWS SDK v3 for JavaScript only (
@aws-sdk/client-dynamodb
and@aws-sdk/util-dynamodb
). 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
Retrieve a value from DynamoDB:
Example
You can also retrieve multiple values at once:
Example
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 values stored as JSON you can use the transform argument for deserialization. This will return a JavaScript object instead of a string.
Example
For values that are instead stored as base64-encoded binary data, you can use the transform argument set to
binary
for decoding. This will return a decoded string.Example
When retrieving multiple values, you can also use the
transform
argument set toauto
to let the provider automatically detect the type of transformation to apply. The provider will use the suffix of the sort key (sk
) to determine the transformation to apply. For example, if the sort key ismy-value-key.json
, the provider will automatically parse the value as JSON. Likewise, if the sort key ismy-value-key.binary
, the provider will automatically decode the value as base64-encoded binary data.Example
Custom key names
By default, the provider will use the following key names:
id
for the partition key,sk
for the sort key, andvalue
for the value. You can adjust the key names by using thekeyAttr
,sortAttr
, andvalueAttr
parameters.Example
Extra SDK options
When retrieving values, you can pass extra options to the AWS SDK v3 for JavaScript client by using the
sdkOptions
parameter.Example
The objects accept the same options as respectively the AWS SDK v3 for JavaScript PutItem command and the AWS SDK v3 for JavaScript DynamoDB client Query command.
Customize AWS SDK v3 for JavaScript client
By default, the provider will create a new DynamoDB 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 DynamoDB client constructor.
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 DynamoDB client.
For more usage examples, see our documentation.