Home > OS >  Reading AWS Param Store from Lambda
Reading AWS Param Store from Lambda

Time:05-24

First foray into AWS's Lambda@Edge and trying to retrieve secrets from AWS Param Store for authentication (following this article) but getting nothing back.

Here's the function that calls the AWS.SSM function:

    const fromParameterStore = async(key, withDecryption = false) => {
        const { Parameter } = await ssm.getParameter({ Name: key, WithDecryption: withDecryption }).promise();
        return Parameter.Value;
    };

And here's how it's called from the main body of the Lambda:

    exports.handler = async (event, context, callback) => {
        const request = event.Records[0].cf.request;
        const testValue = fromParameterStore('my-param-key');
        console.log("test value = " testValue);
        console.log("test value = " JSON.stringify(testValue));
        ...

The output in the log is just this:

testvar = [object Promise]
testvar = {}

How can I cleanly de-reference the Promise in this case to get the actual secret out for use in the rest of the Lambda?

Thanks!

CodePudding user response:

Your fromParameterStore function is asynchronous, so it will return a Promise. You will have to wait for this promise to be fulfilled, meaning you will have to use await when calling fromParameterStore function:

const testValue = await fromParameterStore('my-param-key');
  • Related