ProtectedconfigurationProtectedstoreProtectedvalueProtected_Retrieve a configuration from AWS AppConfig.
First we start the session and after that we retrieve the configuration from AppSync. When starting a session, the service returns a token that can be used to poll for changes for up to 24hrs, so we cache it for later use together with the expiration date.
The value of the configuration is also cached internally because AppConfig returns an empty value if the configuration has not changed since the last poll. This way even if your code polls the configuration multiple times, we return the most recent value by returning the cached one if an empty response is returned by AppConfig.
Name of the configuration or its ID
Optionaloptions: NonNullable<AppConfigGetOptions>SDK options to propagate to StartConfigurationSession API call
Maximum age of the value in the cache, in seconds.
Force fetch the value from the parameter store, ignoring the cache.
Additional options to pass to the AWS SDK v3 client. Supports all options from StartConfigurationSessionCommandInput except ApplicationIdentifier, EnvironmentIdentifier, and ConfigurationProfileIdentifier.
Optional transform to be applied, can be 'json' or 'binary'.
Protected_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 configuration profile from AWS AppConfig.
The name of the configuration profile to retrieve
Optionaloptions: NonNullable<(InferredFromOptionsType & AppConfigGetOptions)>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 StartConfigurationSessionCommandInput except ApplicationIdentifier, EnvironmentIdentifier, and ConfigurationProfileIdentifier
import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig';
const configProvider = new AppConfigProvider({
application: 'my-app',
environment: 'prod',
});
export const handler = async (): Promise<void> => {
// Retrieve a configuration profile
const encodedConfig = await configProvider.get('my-config');
const config = new TextDecoder('utf-8').decode(encodedConfig);
};
Retrieving multiple configurations is not supported by AWS AppConfig.
Optional_options: unknownCheck 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
The Parameters utility provides an
AppConfigProviderthat allows to retrieve configuration profiles from AWS AppConfig.This utility supports AWS SDK v3 for JavaScript only (
@aws-sdk/client-appconfigdata). 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 configs without customizing the provider, you can use the getAppConfig 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
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
Transformations
For configurations stored as freeform JSON, Freature Flag, you can use the transform argument for deserialization. This will return a JavaScript object instead of a string.
Example
For configurations 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
Extra SDK options
When retrieving a configuration profile, you can pass extra options to the AWS SDK v3 for JavaScript client by using the
sdkOptionsparameter.Example
This object accepts the same options as the AWS SDK v3 for JavaScript AppConfigData client.
Customize AWS SDK v3 for JavaScript client
By default, the provider will create a new AppConfigData 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 AppConfig Data 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 AppConfig Data client.
For more usage examples, see our documentation.