Optionalconfig: SSMProviderOptionsProtectederrorsProtectedmaxProtectedstoreProtected_Retrieve a parameter from AWS Systems Manager.
Name of the parameter to retrieve
Optionaloptions: NonNullable<SSMGetOptions>Options to customize the retrieval
Extra options to pass to the AWS SDK v3 for JavaScript client
Whether to decrypt the value before returning it.
Whether to transform the value before returning it. Supported values: json, binary, or auto (default: undefined)
Protected_Retrieve multiple items from AWS Systems Manager.
The path of the parameters to retrieve
Optionaloptions: NonNullable<SSMGetMultipleOptions>Options to configure the provider
The maximum age of the value in cache before fetching a new one (in seconds) (default: 5)
Whether to always fetch a new value from the store regardless if already available in cache
Whether to transform the value before returning it. Supported values: json, binary
Extra options to pass to the AWS SDK v3 for JavaScript client
Whether to throw an error if the transform fails (default: true)
Whether to decrypt the value before returning it.
Whether to recursively retrieve all parameters under the given path (default: false)
Protected_Retrieve multiple items by name from AWS Systems Manager.
An object of parameter names and their options
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
Whether to decrypt the parameters or not
Add a value to the cache.
Key of the cached value
Value to be cached
Maximum age in seconds for the value to be cached
Clear the cache.
Retrieve a value from AWS Systems Manager.
The name of the parameter to retrieve
Optionaloptions: NonNullable<(InferredFromOptionsType & SSMGetOptions)>Optional options to configure the provider
Optional maximum age of the value in the cache, in seconds (default: 5)
Optional flag to always fetch a new value from the store regardless if already available in cache (default: false)
Optional transform to be applied, can be json or binary
Optional additional options to pass to the AWS SDK v3 client, supports all options from GetParameterCommandInput except Name
Optional flag to decrypt the value before returning it (default: false)
Retrieve multiple values from AWS Systems Manager.
The path of the parameters to retrieve
Optionaloptions: NonNullable<(InferredFromOptionsType & SSMGetMultipleOptions)>Optional options to configure the retrieval
Optional maximum age of the value in the cache, in seconds (default: 5)
Optional flag to always fetch a new value from the store regardless if already available in cache (default: false)
Optional transform to be applied, can be json or binary
Optional additional options to pass to the AWS SDK v3 client, supports all options from GetParametersByPathCommandInput | GetParametersByPathCommandInput except Path
Optional flag to throw an error if the transform fails (default: true)
Optional flag to decrypt the value before returning it (default: false)
Optional flag to recursively retrieve all parameters under the given path (default: false)
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
const parametersProvider = new SSMProvider();
export const handler = async (): Promise<void> => {
// Retrieve multiple parameters from SSM
const parameters = await parametersProvider.getMultiple('/my-parameters-path');
};
For usage examples check SSMProvider.
ProtectedgetSlice batch and fetch parameters using GetPrameters API by max permissible batch size
An object of parameter names and their options
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
Whether to decrypt the parameters or not
Retrieve multiple parameters by name from AWS Systems Manager.
Object containing parameter names and any optional overrides
Optionaloptions: SSMGetParametersByNameOptionsOptions to configure the retrieval
Options for the SSMProvider getParametersByName method.
Optionaldecrypt?: booleanIf true, the parameter will be decrypted.
OptionalmaxAge?: numberMaximum age of the value in the cache, in seconds.
OptionalthrowOnError?: booleanIf true, the method will throw an error if one of the parameters cannot be fetched. Otherwise it will aggregate the errors under an _errors key in the response.
Optionaltransform?: "json" | "binary"Transform to be applied, can be 'json' or 'binary'.
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
const parametersProvider = new SSMProvider();
export const handler = async (): Promise<void> => {
// Retrieve multiple parameters by name from SSM
const parameters = await parametersProvider.getParametersByName({
'/my-parameter-1': {}, // Use default options
'/my-parameter-2': { transform: 'json' }, // Parse the value as JSON
});
};
The throwOnError option decides whether to throw an error if a parameter is not found:
GetParameterError error upon any failure.It transparently uses GetParameter and/or GetParameters depending on decryption requirements.
┌────────────────────────┐
┌───▶ Decrypt entire batch │─────┐
│ └────────────────────────┘ │ ┌────────────────────┐
│ ├─────▶ GetParameters API │
┌──────────────────┐ │ ┌────────────────────────┐ │ └────────────────────┘
│ Split batch │─── ┼──▶│ No decryption required │─────┘
└──────────────────┘ │ └────────────────────────┘
│ ┌────────────────────┐
│ ┌────────────────────────┐ │ GetParameter API │
└──▶│Decrypt some but not all│───────────▶────────────────────┤
└────────────────────────┘ │ GetParameters API │
└────────────────────┘
ProtectedgetFetch each parameter from batch that hasn't expired from cache
An object of parameter names and their options
ProtectedgetSlice object into chunks of max permissible batch size and fetch parameters
An object of parameter names and their options
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
Whether to decrypt the parameters or not
ProtectedgetFetch parameters by name while also decrypting them
An object of parameter names and their options
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
Check whether a key has expired in the cache or not.
It returns true if the key is expired or not present in the cache.
Stringified representation of the key to retrieve
ProtectedresolveOptionalsdkOptions: GetParameterCommandInput | GetParametersByPathCommandInputSets a parameter in AWS Systems Manager (SSM).
The name of the parameter
Options to configure the parameter
Optionaldescription?: stringThe description of the parameter
OptionalkmsKeyId?: stringThe KMS key id to use to encrypt the parameter
Optionaloverwrite?: booleanIf the parameter value should be overwritten
OptionalparameterType?: ParameterTypeType of the parameter, can be one of String, StringList, or SecureString
OptionalsdkOptions?: Partial<PutParameterCommandInput>Additional options to pass to the AWS SDK v3 client
Optionaltier?: ParameterTierThe parameter tier to use, can be one of Standard, Advanced, and Intelligent-Tiering
The parameter value
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
const parametersProvider = new SSMProvider();
export const handler = async (): Promise<void> => {
// Set a parameter in SSM
const version = await parametersProvider.set('/my-parameter', { value: 'my-value' });
console.log(`Parameter version: ${version}`);
};
ProtectedtransformTransform and cache the response from GetParameters API call
The response from the GetParameters API call
An object of parameter names and their options
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
Protected StatichandleHandle any invalid parameters returned by GetParameters API.
GetParameters is non-atomic. Failures don't always reflect in exceptions so we need to collect.
The result of the GetParameters API call
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
Protected StaticsplitSplit parameters that can be fetched by GetParameters vs GetParameter.
An object of parameter names and their options
The configs passed down
Protected StaticthrowThrow a GetParameterError if fail-fast is disabled and _errors key is in parameters list.
An object of parameter names and their options
The reserved parameter name that cannot be used when fail-fast is disabled
Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
The Parameters utility provides a
SSMProviderthat allows to retrieve parameters from AWS Systems Manager.This utility supports AWS SDK v3 for JavaScript only (
@aws-sdk/client-ssm). 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 parameter from SSM:
Example
If you want to retrieve a parameter without customizing the provider, you can use the getParameter function instead.
You can also retrieve parameters at once. If you want to get multiple parameters under the same path, you can use the
getMultiplemethod.Example
If you don't need to customize the provider, you can also use the getParameters function instead.
If instead you want to retrieve multiple parameters by name, you can use the
getParametersByNamemethod.Example
If you don't need to customize the provider, you can also use the getParametersByName function instead.
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
maxAgeparameter.Example
When using the
getParametersByNamemethod, you can set a differentmaxAgefor each parameter or set a defaultmaxAgefor all parameters.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
forceFetchparameter.Example
Likewise, you can use the
forceFetchparameter with thegetParametersByNamemethod both for individual parameters and for all parameters.Decryption
If you want to retrieve a parameter that is encrypted, you can use the
decryptparameter. This parameter is compatible withget,getMultipleandgetParametersByName.Example
Transformations
For parameters stored as JSON you can use the transform argument for deserialization. This will return a JavaScript object instead of a string.
Example
For parameters that are instead stored as base64-encoded binary data, you can use the transform argument set to
binaryfor decoding. This will return a decoded string.Example
Both type of transformations are compatible also with the
getParametersByNamemethod.Extra SDK options
When retrieving parameters, you can pass extra options to the AWS SDK v3 for JavaScript client by using the
sdkOptionsparameter.Example
The objects accept the same options as respectively the AWS SDK v3 for JavaScript GetParameter command and the AWS SDK v3 for JavaScript GetParametersByPath command.
Customize AWS SDK v3 for JavaScript client
By default, the provider will create a new SSM 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 SSM 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 SSM client.
For more usage examples, see our documentation.