-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-lambda.ts
51 lines (42 loc) · 1.05 KB
/
update-lambda.ts
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
import {
LambdaClient,
UpdateFunctionCodeCommand
} from '@aws-sdk/client-lambda';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { readFileSync } from 'fs';
const FunctionName = process.argv[2];
const path = process.argv[3];
const region = process.argv[4] || 'eu-central-1';
console.log('deploying lambda function', {
region,
FunctionName,
path
});
if (!FunctionName) {
throw new Error('please provide a FunctionName');
}
if (!path) {
throw new Error('please provide a path to a zip-file');
}
const ZipFile = readFileSync(path);
const s3 = new S3Client();
const Bucket = `report-royal-lambda-${region}`;
const Key = FunctionName;
s3.send(
new PutObjectCommand({
Bucket,
Key,
Body: ZipFile
})
).then(async () => {
const lambda = new LambdaClient();
const result = await lambda.send(
new UpdateFunctionCodeCommand({
FunctionName,
S3Bucket: Bucket,
S3Key: Key,
Publish: true
})
);
console.log(result);
});