-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (87 loc) · 2.8 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const { getInput, info: logInfo, setFailed } = require("@actions/core");
const { LambdaClient, PublishLayerVersionCommand } = require("@aws-sdk/client-lambda");
const { readFileSync } = require("fs");
/**
* @typedef {import("@aws-sdk/client-lambda").LambdaClient} LambdaClient
* @typedef {import("@aws-sdk/client-lambda").LambdaClientConfig} LambdaClientConfig
* @typedef {import("@aws-sdk/client-lambda").PublishLayerVersionCommand} PublishLayerVersionCommand
* @typedef {import("@aws-sdk/client-lambda").PublishLayerVersionCommandInput} PublishLayerVersionCommandInput
* @typedef {import("@aws-sdk/client-lambda").PublishLayerVersionCommandOutput} PublishLayerVersionCommandOutput
*/
/**
* @type {LambdaClient}
*/
let client;
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
if (!accessKeyId) {
setFailed("AWS_ACCESS_KEY_ID not set in environment");
}
if (!secretAccessKey) {
setFailed("AWS_SECRET_ACCESS_KEY not set in environment");
}
try {
/**
* @type {LambdaClientConfig}
*/
const clientConfig = {
region: process.env.AWS_REGION || "us-east-1",
maxAttempts: 2,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
};
client = new LambdaClient(clientConfig);
logInfo("LambdaClient created successfully...");
} catch (e) {
setFailed(e);
}
/**
* @type {PublishLayerVersionCommand}
*/
let command;
try {
const LayerName = getInput("layer_name", { required: true });
const layerFile = getInput("zip_file", { required: true });
const Description = getInput("layer_desc", { required: false });
const archStr = getInput("arch", { required: false });
const runtimeStr = getInput("runtime", { required: false });
const commandOptions = {
LayerName,
Content: {
ZipFile: readFileSync(layerFile),
},
};
if (Description) {
commandOptions.Description = Description;
}
if (archStr) {
const arch = archStr.replaceAll(/\s/g, "");
commandOptions.CompatibleArchitectures = arch.split(",");
}
if (runtimeStr) {
const runtime = runtimeStr.replaceAll(/\s/g, "");
commandOptions.CompatibleRuntimes = runtime.split(",");
}
command = new PublishLayerVersionCommand(commandOptions);
console.log({ command });
logInfo("LambdaClient Command created successfully...");
} catch (e) {
setFailed(e);
}
async function publish() {
try {
/**
* @type {PublishLayerVersionCommandOutput}
*/
const response = await client.send(command);
if (response && response["$metadata"].httpStatusCode < 300) {
logInfo("New layer version published successfully");
logInfo(`Layer version ARN: ${response.LayerVersionArn}, Version: ${response.Version}`);
}
} catch (e) {
setFailed(e);
}
}
publish();