我正在尝试在 lamda 函数中使用 pupeteer,并使用 @sparticuz/chromium-min 将 brotli 文件托管在 S3 存储桶中... 我通过无服务器框架创建 S3 存储桶,然后通过控制台手动上传 .tar 文件。 运行该函数时,我不断收到“数据意外结束”错误。
这是来自我的 serverless.yml :
iam:
role:
statements:
- Effect: 'Allow'
Action:
- s3:*
Resource: !GetAtt ChromiumBucket.Arn
resources:
Resources:
ChromiumBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: chromium-pupeteer-bucket
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- POST
- PUT
AllowedOrigins:
- "*"
AllowedHeaders:
- "*"
functions:
createPDF:
handler: src/pdf/pdf.handler
events:
- httpApi:
path: /pdf
method: post
和功能:
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium-min");
module.exports.handler = async (event) => {
console.log("we got this far")
const { pdfUrl } = JSON.parse(event.body)
console.log(pdfUrl)
const chromiumPackUrl = "https://bucket-name.s3.region.amazonaws.com/file.tar"
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(chromiumPackUrl),
headless: chromium.headless,
ignoreHTTPSErrors: true
});
console.log(browser)
}
你的S3是公开的吗?我遇到了这个问题,我通过更改存储桶的隐私解决了它