forked from claudiajs/claudia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-code.js
34 lines (34 loc) · 983 Bytes
/
lambda-code.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
const path = require('path'),
fs = require('fs'),
fsPromise = require('../util/fs-promise'),
readFromDisk = function (packageArchive) {
'use strict';
return fsPromise.readFileAsync(packageArchive)
.then(fileContents => ({ ZipFile: fileContents }));
},
uploadToS3 = function (s3, filePath, bucket, serverSideEncryption, s3Key) {
'use strict';
const fileKey = s3Key ? s3Key : path.basename(filePath),
params = {
Bucket: bucket,
Key: fileKey,
Body: fs.createReadStream(filePath),
ACL: 'private'
};
if (serverSideEncryption) {
params.ServerSideEncryption = serverSideEncryption;
}
return s3.upload(params).promise()
.then(() => ({
S3Bucket: bucket,
S3Key: fileKey
}));
};
module.exports = function lambdaCode(s3, zipArchive, s3Bucket, s3ServerSideEncryption, s3Key) {
'use strict';
if (!s3Bucket) {
return readFromDisk(zipArchive);
} else {
return uploadToS3(s3, zipArchive, s3Bucket, s3ServerSideEncryption, s3Key);
}
};