使用AWS Lambda打包S3文件
首先创建lambda函数:
const AWS = require('aws-sdk') const s3Zip = require('s3-zip') exports.handler = function (event, context) { console.log('event', event) const region = event.region const bucket = event.bucket const folder = event.folder const files = event.files const zipFileName = event.zipFileName // Create body stream try { const body = s3Zip.archive({ region: region, bucket: bucket}, folder, files) const zipParams = { params: { Bucket: bucket, Key: folder + zipFileName } } const zipFile = new AWS.S3(zipParams) zipFile.upload({ Body: body }) .on('httpUploadProgress', function (evt) { console.log(evt) }) .send(function (e, r) { if (e) { const err = 'zipFile.upload error ' + e console.log(err) context.fail(err) } console.log(r) context.succeed(r) }) } catch (e) { const err = 'catched error: ' + e console.log(err) context.fail(err) } }
调用lambda函数:
const AWS = require('aws-sdk') const region = 'bucket-region' const bucket = 'name-of-s3-bucket' const folder = 'name-of-bucket-folder/' const file1 = 'Image A.png' const file2 = 'Image B.png' const file3 = 'Image C.png' const file4 = 'Image D.png' AWS.config.update({ region: region }) const lambda = new AWS.Lambda() const files = [file1, file2, file3, file4] const payload = JSON.stringify({ 'region' : region, 'bucket' : bucket, 'folder' : folder, 'files' : files, 'zipFileName': 'bla.zip' }) const params = { FunctionName : 'NAME_OF_YOUR_LAMBDA_FUNCTION', Payload : payload } lambda.invoke(params, function (err, data) { if (err) console.log(err, err.stack) // an error occurred else console.log(data) // successful response })
上传lambda压缩包:
https://docs.aws.amazon.com/l...
使用go来调用lambda函数:
相关推荐
byn 2020-11-19
Dancen 2020-10-20
guchengxinfen 2020-10-12
SirLZF 2020-10-10
evolone 2020-10-09
AWS爽 2020-09-21
wolfjin 2020-09-10
lilu 2020-09-08
frank0 2020-08-26
wl00 2020-08-26
QFYJTL 2020-08-23
JokerCch 2020-08-17
zwb 2020-08-14
bendan 2020-08-13
酌希 2020-08-04
快乐de馒头 2020-07-29
Dramer0 2020-07-09
黑夜流星 2020-06-28
swazerz 2020-06-22