It initializes the SSMProvider class.
Optional
config: SSMProviderOptionsThe configuration object.
Protected
errorsProtected
maxProtected
storeProtected
_getRetrieve a parameter from AWS Systems Manager.
Name of the parameter to retrieve
Optional
options: SSMGetOptionsOptions to customize the retrieval
Protected
_getRetrieve multiple items from AWS Systems Manager.
The path of the parameters to retrieve
Optional
options: SSMGetMultipleOptionsOptions to configure the provider
Protected
_getRetrieve 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
Retrieve a value from AWS Systems Manager.
The name of the value to retrieve (i.e. the partition key)
Optional
options: InferredFromOptionsType & SSMGetOptionsOptions to configure the provider
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
const parametersProvider = new SSMProvider();
export const handler = async (): Promise<void> => {
// Retrieve a parameter from SSM
const parameter = await parametersProvider.get('/my-parameter');
};
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 clientdecrypt
- Whether to decrypt the value before returning it.For usage examples check SSMProvider.
Retrieve multiple values from AWS Systems Manager.
The path of the parameters to retrieve
Optional
options: InferredFromOptionsType & SSMGetMultipleOptionsOptions to configure the retrieval
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');
};
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
)decrypt
- Whether to decrypt the value before returning it.recursive
- Whether to recursively retrieve all parameters under the given path (default: false
)For usage examples check SSMProvider.
Protected
getSlice 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
Optional
options: SSMGetParametersByNameOptionsOptions to configure the retrieval
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
});
};
You can customize the retrieval of the values by passing options to both the function and the parameter:
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
)decrypt
- Whether to decrypt the value before returning itthrowOnError
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 │
└────────────────────┘
Protected
getFetch each parameter from batch that hasn't expired from cache
An object of parameter names and their options
Protected
getSlice 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
Protected
getFetch 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
Protected
resolveOptional
sdkOptions: GetParameterCommandInput | GetParametersByPathCommandInputSets a parameter in AWS Systems Manager (SSM).
The name of the parameter
Options to configure the parameter
The version of the parameter
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}`);
};
You can customize the storage of the value by passing options to the function:
value
- The value of the parameter, which is a mandatory option.overwrite
- Whether to overwrite the value if it already exists (default: false
)description
- The description of the parameterparameterType
- The type of the parameter, can be one of String
, StringList
, or SecureString
(default: String
)tier
- The parameter tier to use, can be one of Standard
, Advanced
, and Intelligent-Tiering
(default: Standard
)kmsKeyId
- The KMS key id to use to encrypt the parametersdkOptions
- Extra options to pass to the AWS SDK v3 for JavaScript clientProtected
transformTransform 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
Static
handleHandle 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
Static
splitSplit parameters that can be fetched by GetParameters vs GetParameter.
An object of parameter names and their options
The configs passed down
Protected
Static
throwThrow a GetParameterError if fail-fast is disabled and _errors
key is in parameters list.
Intro
The Parameters utility provides a SSMProvider that allows to retrieve parameters from AWS Systems Manager.
Getting started
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
getMultiple
method.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
getParametersByName
method.Example
If you don't need to customize the provider, you can also use the getParametersByName 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
When using the
getParametersByName
method, you can set a differentmaxAge
for each parameter or set a defaultmaxAge
for 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
forceFetch
parameter.Example
Likewise, you can use the
forceFetch
parameter with thegetParametersByName
method both for individual parameters and for all parameters.Decryption
If you want to retrieve a parameter that is encrypted, you can use the
decrypt
parameter. This parameter is compatible withget
,getMultiple
andgetParametersByName
.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
binary
for decoding. This will return a decoded string.Example
Both type of transformations are compatible also with the
getParametersByName
method.Extra SDK options
When retrieving parameters, 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 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.