UNPKG

ssm-parameters

Version:

Lightweight AWS Parameter Store wrapper

106 lines (105 loc) 3.81 kB
import { SSM } from 'aws-sdk'; /** * Options for the *SSMParameters*. */ export interface SSMParametersOptions { /** Return decrypted values for secure string parameters */ withDecryption?: boolean; /** Maximum number of seconds the parameters will be considered fresh */ maxAge?: number; /** https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SSM.html */ ssmConfiguration?: SSM.ClientConfiguration; } /** * Options when loading or getting the parameters. */ export interface SSMParametersLoadOptions { /** Ignore any existing cache and load the parameters */ ignoreCache: boolean; } /** * Class responsible to load and cache parameters from the AWS SSM Parameters * Store. */ export declare class SSMParameters<Parameters extends Record<string, string>> { private readonly DEFAULT_WITH_DECRYPTION; private readonly DEFAULT_MAX_AGE_IN_SECONDS; private readonly MAX_PARAMETERS_PER_REQUEST; private readonly withDecryption; private readonly maxAge; private readonly ssmClient; private parametersName; private parametersValue; private parameterLoaded; private lastLoadTime; /** * Create an instance of the *SSMParameters*. * * @example * new SSMParameters({ LogLevel: '/LogLevel' }); * new SSMParameters({ LogLevel: '/LogLevel' }, { maxAge: 60 }); * * @param parameters Map with parameter's keys and parameter's names on AWS. * @param options *SSMParametersOptions* */ constructor(parameters: Parameters, options?: SSMParametersOptions); /** * Load parameters from AWS SSM Parameter Store. * * @note * - If the parameters have not been loaded yet, they will be loaded. * - If the parameters have been loaded and cache didn't expired yet, * it uses the cache. * - If the parameters have been loaded but the cache has expired, it loads * the parameters again. * * @param options *SSMParametersLoadOptions* * @returns Promise to when parameters have been loaded or cache is used. */ load(options?: SSMParametersLoadOptions): Promise<void>; /** * Get parameter. * * @note * - If the parameters have not been loaded yet, they will be loaded. * - If the parameters have been loaded and cache didn't expired yet, * it uses the cache. * - If the parameters have been loaded but the cache has expired, it loads * the parameters again. * * @param key Key of the parameter. * @param options *SSMParametersLoadOptions* * @returns Promise to parameter's value or undefined if it does not exist. */ get(key: keyof Parameters, options?: SSMParametersLoadOptions): Promise<string | undefined>; /** * Get parameters. * * @note * - If the parameters have not been loaded yet, they will be loaded. * - If the parameters have been loaded and cache didn't expired yet, * it uses the cache. * - If the parameters have been loaded but the cache has expired, it loads * the parameters again. * * @param options *SSMParametersLoadOptions* * @returns Promise to all parameters. */ getAll(options?: SSMParametersLoadOptions): Promise<Record<keyof Parameters, string | undefined>>; /** * Get parameters to load. * * @note The array returned by this function contains a maximum number of * parameters defined by `MAX_PARAMETERS_PER_REQUEST`. * * @returns Array of parameters to load. */ private getParametersToLoad; /** * Load parameters from AWS SSM. * * @param parameters Parameters to load from AWS SSM. * @returns Promise to when parameters have been loaded. */ private loadParameters; }