-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssm-helper.js
53 lines (50 loc) · 1.4 KB
/
ssm-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const AWS = require("aws-sdk");
const getParameter = async (ssmPath, decryption, region) => {
AWS.config.update({ region: region });
const ssm = new AWS.SSM();
const params = {
Name: ssmPath,
WithDecryption: decryption,
};
const result = await ssm.getParameter(params).promise();
return result.Parameter.Value;
};
const createSsmValue = async (
ssmPath,
region,
ssmValue,
ssmType,
core,
nullable
) => {
try {
core.info(`Storing Variable in path [${ssmPath}]`);
// Load the AWS Region to use in SSM
core.debug(`Setting aws-region [${region}]`);
AWS.config.update({ region: region });
const ssm = new AWS.SSM();
const params = {
Name: ssmPath,
Value: ssmValue,
Type: ssmType,
Overwrite: false,
};
const keyId = core.getInput("ssm-kms-key-id");
if (params["Type"] === "SecureString" && keyId !== "") {
core.debug(`Setting the KeyId to ${keyId}`);
params["KeyId"] = keyId;
}
const result = await ssm.putParameter(params).promise();
core.debug(
`Parameter details Version [${result.Version}] Tier [${result.Tier}]`
);
core.info(`Successfully Stored parameter in path [${ssmPath}]`);
} catch (error) {
if (!nullable) {
core.setFailed(error.message);
} else {
core.debug(`could not find parameter: ${error.message}`);
}
}
};
module.exports = { getParameter, createSsmValue };