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.
Obtain the value using Node
Here is a library I created stored on gist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
1
2
3
4
5
6
7
8
9
import { getEncryptedParameter } from "./parameterStore";
.
.
.
const twilioSID = await getEncryptedParameter("TWILIO_ACCOUNT_SID");
.
.
.
This post is licensed under CC BY 4.0 by the author.