Skip to content

Instantly share code, notes, and snippets.

@SalvoCozzubo
Created February 3, 2022 19:07
Show Gist options
  • Save SalvoCozzubo/4502fc9c2c598fd344ba061915760136 to your computer and use it in GitHub Desktop.
Save SalvoCozzubo/4502fc9c2c598fd344ba061915760136 to your computer and use it in GitHub Desktop.
Handler
const { SSMClient, GetParameterCommand } = require('@aws-sdk/client-ssm');
const AWSXRay = require('aws-xray-sdk');
// code outside the handler
const client = AWSXRay.captureAWSv3Client(new SSMClient({}));
let value;
module.exports.handler = async () => {
// check if values is cached
if (!value) {
const params = {
Name: process.env.SSM_PARAMETER,
};
const { Parameter } = await client.send(new GetParameterCommand(params));
value = Parameter.Value;
}
return value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment