This is a note to my future self on how to retrieve SSM parameters from AWS with Nodejs. SSM (Systems Manager) is a service provided by AWS that allows you to securely store and retrieve data for your application (amongst other things). This can be environment based connection urls, authentication credentials, or properties you’d like to change without needing a re-deploy of your application.

Retrieving a parameter is pretty simple. In this example, I stored the following data in SSM at the key super-secret-api-auth. Note, SSM can store strings, list of strings, or secure strings (encrypted). I chose to store a JSON string because I can serialize it into a JavaScript object in Node.

{
    "key": "this-is-a-secret-key",
    "secret": "this-is-a-key-secret"
}

This string should be encrypted. Note when I retrive it, I tell SSM to decrypt the value first.

const AWS = require('aws-sdk');

(async() => {
    const ssm = new AWS.SSM();
    const parameter = await ssm.getParameter({ 
        Name: 'super-secret-api-auth', 
        WithDecryption: true 
    }).promise();
    const data = JSON.parse(parameter.Parameter.Value);
    console.log(data); // prints the json from above
    /*
    {
        key: "this-is-a-secret-key",
        secret: "this-is-a-key-secret"
    }
    */
})();
🧇