-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (50 loc) · 1.92 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
const core = require('@actions/core');
const github = require('@actions/github');
import Lambda from 'aws-sdk/clients/lambda';
const run = async () => {
try {
// Extract name
const lambda_function_name = core.getInput('function_name', { required: true });
const lambda_config = {
accessKeyId: core.getInput('aws_access_key_id', { required: true }),
apiVersion: '2015-03-31',
maxRetries: 2,
region: core.getInput('aws_region', { required: true }),
secretAccessKey: core.getInput('aws_secret_access_key', { required: true }),
sslEnabled: true
};
// Create lambda API client
const lambda = new Lambda(lambda_config);
core.info("Getting lambda layers for function");
const lambda_function_data = await lambda.getFunctionConfiguration({
FunctionName: lambda_function_name,
}).promise();
core.info("Received lambda function information");
const layers = lambda_function_data.Layers;
if (layers == null
|| layers == undefined
|| layers.length == 0) {
core.info("No layers present for function");
}
core.info("Updating " + lambda_function_data.Layers.length + " for function");
const new_layer_list = [];
for (let i = 0; i < layers.length; ++i) {
const layer = lambda_function_data.Layers[i];
const lambda_layer_data = await lambda.listLayerVersions({
LayerName: layer.Arn.substring(0, layer.Arn.lastIndexOf(":"))
}).promise();
core.info("Recieved lambda versions for layer (" + (i + 1) + "/" + layers.length + ")");
const target_layer = lambda_layer_data.LayerVersions.sort((a, b) => b.Version - a.Version)[0];
new_layer_list.push(target_layer.LayerVersionArn);
}
core.info("Updating function layer versions");
const update_lambda_config = await lambda.updateFunctionConfiguration({
FunctionName: lambda_function_name,
Layers: new_layer_list
}).promise();
core.info("Layer update success");
} catch (error) {
core.setFailed(error.message);
}
};
run();