小编Rab*_*ona的帖子

使用Lambda Node从S3上的文件创建S3上的zip文件

我需要创建一个Zip文件,其中包含位于我的s3存储桶中的一系列文件(视频和图像).

目前使用我的代码的问题是我很快就达到了Lambda的内存限制.

async.eachLimit(files, 10, function(file, next) {
    var params = {
        Bucket: bucket, // bucket name
        Key: file.key
    };
    s3.getObject(params, function(err, data) {
        if (err) {
            console.log('file', file.key);
            console.log('get image files err',err, err.stack); // an error occurred
        } else {
            console.log('file', file.key);
            zip.file(file.key, data.Body);
            next();
        }
    });
}, 
function(err) {
    if (err) {
        console.log('err', err);
    } else {
        console.log('zip', zip);
        content = zip.generateNodeStream({
            type: 'nodebuffer',
            streamFiles:true
        });
        var params = {
            Bucket: bucket, // name of dest bucket
            Key: 'zipped/images.zip', …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services node.js aws-lambda

17
推荐指数
3
解决办法
9814
查看次数

API网关无法解码base64

我试图使用基于节点的lambda函数通过API网关从s3返回jpeg图像。

我的Lambda函数显示为:

s3.getObject(params).promise().then((result) => { 
    let resp = {
                statusCode: 200,
                headers: {
                    'Content-Type': 'image/jpeg'
                },
                body: result.Body.toString('base64'),
                isBase64Encoded: true
    };          
    callback(null, resp);
});
Run Code Online (Sandbox Code Playgroud)

我还将API网关中的集成响应修改为“转换为二进制文件(如果需要)”。当我尝试测试此功能时,我收到错误消息“由于配置错误,执行失败:无法对主体进行base64解码。”。

我是否缺少允许我检索base64编码文件的步骤?

aws-lambda aws-api-gateway

5
推荐指数
1
解决办法
2985
查看次数