Skip to content

Instantly share code, notes, and snippets.

@fl0wo
Last active December 12, 2022 20:56
Show Gist options
  • Save fl0wo/0ba46fcda1aa6bbcd0f2f22daf0b1fda to your computer and use it in GitHub Desktop.
Save fl0wo/0ba46fcda1aa6bbcd0f2f22daf0b1fda to your computer and use it in GitHub Desktop.
Cool AWS SSM Functions utils for PUT/GET/DELETE keys
import {SSM} from "aws-sdk";
export async function getParameterValue(parameterName: string) {
const param = await new SSM()
.getParameter({Name: parameterName,WithDecryption: true})
.promise();
const value = param.Parameter?.Value as string;
if (!value) throw new Error(`Can not find SSM parameter with name ${parameterName}`);
return value;
}
export async function putParameterValue(paramName:string,paramValue: string) {
const param = await new SSM()
.putParameter({
Name: paramName,
Description: 'Api Secret Key of a DipSway user.',
Value: paramValue,
Type:'String'
})
.promise();
const err = param.$response.error;
if (!!err) throw new Error(`Can not insert SSM parameter with name ${paramName}`);
return param;
}
export async function removeParameterValue(paramName:string) {
const param = await new SSM()
.deleteParameter({Name: paramName})
.promise();
const err = param.$response.error;
if (!!err)throw new Error(`Can not insert SSM parameter with name ${paramName}`);
return param;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment