Odd Response from AWS SSM Request

219 views Asked by At

I refactored my code based on Marcin's suggestion so I am calling SSM to retrieve a particular value (this is in an awsUtils.js file):

const AWS = require("aws-sdk");
const ssm = new AWS.SSM({region: process.env.AWS_REGION});

async function executeParameterCall(ssmParameter) {
    const params = {
        Name: ssmParameter, 
        WithDecryption: false
    };
    
    console.debug("params", params);

    var request = await ssm.getParameter(params).promise();
    
    return request.Parameter.Value;          
}

module.exports.getSSMValue = async (ssmParameter) => {
    return = await executeParameterCall(ssmParameter);
}

and I am calling it from my NodeJS lambda:

const someValue = awsUtils.getSSMValue(process.env.ACCOUNT_VALUE);

I would expect to have returned to my lambda:

json
{
    "Parameter": {
        "Name": "/dev/account/someValue",
        "Type": "String",
        "Value": "{\"key\": \"foo\"\}",
        "Version": 1,
        "LastModifiedDate": "2020-10-08T21:04:17.451000-05:00",
        "ARN": "arn:aws:ssm:us-east-2:038017203494:parameter/dev/account/someValue",
        "DataType": "text"
    }
}

but I what do get back is:

Promise { <pending> }

I have confirmed that the correct values are returned if I call SSM through the CLI.

So, is there something I am missing in this AWS request or the structure of my code that is causing this response?

1

There are 1 answers

2
Marcin On

I think you are incorrectly calling your getParameter method. Here are some example how it should be called.

Specifically, the following example can be useful in your case:

    const ssmRequest = await ssm.getParameter({Name: ssmParamter, WithDecryption: true}).promise();
        
    console.debug("ssmResponse", ssmRequest.Parameter.Value);