Retrieving Parameters in the AWS Parameter Store with Node/Typescript

Summary

If you are storing secrets (passwords/keys) in AWS you can use a few different methods. Please do not keep in them in your repos or in your source code! Two popular methods on AWS are Parameters in the SSM Parameter store OR using the AWS Secrets Manager. The Parameter store is free but there is no SLA on performance. The Secrets Manager is expensive.

Parameter Store

First, create a parameter (encrypted or not). You do this from SSM –> Parameter Store –> Create.
aws-parameter-store

Obtain the value using Node

Here is a library I created stored on gist

import { SSM } from "aws-sdk";

const getParameterWorker = async (name:string, decrypt:boolean) : Promise<string> => {
    const ssm = new SSM();
    const result = await ssm
    .getParameter({ Name: name, WithDecryption: decrypt })
    .promise();
    return result.Parameter.Value;
}

export const getParameter = async (name:string) : Promise<string> => {
    return getParameterWorker(name,false);
}

export const getEncryptedParameter = async (name:string) : Promise<string> => {
    return getParameterWorker(name,true);
}

Using the function(s)

import { getEncryptedParameter } from "./parameterStore";
.
.
.
  const twilioSID = await getEncryptedParameter("TWILIO_ACCOUNT_SID");
.
.
.

[ dev aws node serverless ]