Alex Ketchum
01/10/2022, 9:05 PM// Node.js file
const {a,b,c} = process.env
module.exports.lambdaHandler1 = async () => {
console.log(a)
helperFunction1()
}
function helperFunction1() {
console.log(b)
}
module.exports.lambdaHandler2 = async () => {
console.log(c)
}
We want to switch to using the AWS Node SDK getParameters function to get the parameters at run time. Does anyone have any suggestions for calling the get parameters function at the top of the lambda handler file to simplify variable declaration for these variables that will be shared across many functions? This is an async function, so i cant await the function call at the top level, since it is outside any async functions.
My immediate first idea was a simple change to something like below, but this does not work due to the getParameters call being async.
// Node.js file
// This wont work because you can not use await outside an async function
const {a,b,c} = await AWS.SSM().getParameters(['/path/to/a', '/path/to/b', '/path/to/c'])
module.exports.lambdaHandler1 = async () => {
console.log(a)
helperFunction1()
}
function helperFunction1() {
console.log(b)
}
module.exports.lambdaHandler2 = async () => {
console.log(c)
}
What I really want to avoid is calling the “getParameters” function inside each lambda handler. That results in a lot of duplicate code and means that any helper function where we want to use an environment variable (like a database name) must be asynchronous or updated to take the env var as a parameter, which is unnecessary for many of these helper functionsSeth Geoghegan
01/10/2022, 9:18 PMAdam Fanello
01/10/2022, 9:22 PMAlex Ketchum
01/10/2022, 9:38 PMAdam Fanello
01/10/2022, 9:41 PMSeth Geoghegan
01/10/2022, 9:44 PMthdxr
01/10/2022, 9:56 PMthdxr
01/10/2022, 9:56 PMthdxr
01/10/2022, 9:57 PMdeasync
to pause the nodejs event loop so that it fetches synchronously. It works but is terriblethdxr
01/10/2022, 9:57 PMthdxr
01/10/2022, 9:58 PMthdxr
01/10/2022, 9:59 PMprocess.env
because it forces you to add another dependency injection layer outside the base module systemAlex Ketchum
01/10/2022, 10:24 PMAdam Fanello
01/10/2022, 10:34 PM