将屏幕快照从AWS lambda上传到s3存储桶失败 [英] Uploading screenshot from AWS lambda to s3 bucket fails

查看:149
本文介绍了将屏幕快照从AWS lambda上传到s3存储桶失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用aup lambda上的puppeteer截屏并将其上传到s3存储桶.但是,s3.putObject方法似乎不起作用.在lambda控制台上,我同时收到上传屏幕快照's3://$ {s3bucket}/$ {filename}'"和上传完成"消息,但未收到内部回调"消息.奇怪的是,在执行lambda的过程中我没有出现任何错误,但是我只是无法在putObject方法中获取消息,也无法在存储桶中找到屏幕截图.谁能给我一些关于调试的建议?

I am trying to take screenshots with puppeteer on aws lambda and upload the screenshot to a s3 bucket. However, the s3.putObject method doesn't seem to be working. On the lambda console, I got both the "uploading screenshot 's3://${s3bucket}/${filename}'" and "uploading completed" message but not the "inside callback" message. The weird thing is, I got no error during the lambda execution, but I just couldn't get the message inside the putObject method and couldn't find the screenshots in the bucket. Can anyone give me some suggestion on how to debug?

const aws = require('aws-sdk');
const s3 = new aws.S3({ apiVersion: '2006-03-01' });

module.exports.saveScreenshotToS3 = async(page, s3bucket, filename) => {
    let buffer = await page.screenshot({encoding: "base64"});
    console.log(`Uploading screenshot 's3://${s3bucket}/${filename}'`);
    const s3Params = {
        Bucket: s3bucket,
        Key: filename,
        Body: buffer
    };
    await s3.putObject(s3Params, (err, data) => {
        console.log("inside callback");
        if (err) {
            console.log(err);
        } else {
            console.log("uploading succeeded");
        }
    }).promise();
    console.log("uploading completed");

}

推荐答案

已解决.

我只更改了存储桶策略中的权限,却忘记了更改CORS配置,这就是导致我的功能失败的原因.

I only changed permission in bucket policy and forgot to change the CORS configuration, and that's what made my function fail.

我将<AllowedMethod> PUT </AllowedMethod>添加到了我的CORS配置脚本中,并且上传成功.

I added <AllowedMethod> PUT </AllowedMethod> to my CORS configuration script and the uploading works.

请记住同时更改存储桶策略和CORS配置,以便您具有将文件上传到存储桶的正确权限.

Remember to change both the bucket policy and CORS configuration so that you have the right permission to upload files to your bucket.

这篇关于将屏幕快照从AWS lambda上传到s3存储桶失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆