【发布时间】:2021-04-05 15:02:11
【问题描述】:
我有一个用例,我必须读取一个 ZIP 文件并将其作为模板传递给 lambda 的创建。 现在我想从 S3 公共存储桶中读取 zip 文件。如何从公共存储桶中读取文件?
我正在阅读的 S3 存储桶 zip 文件是 https://lambda-template-code.s3.amazonaws.com/LambdaTemplate.zip
const zipContents = 'https://lambda-template-code.s3.amazonaws.com/LambdaTemplate.zip';
var params = {
Code: {
// here at below I have to pass the zip file reading it from the S3 public bucket
ZipFile: zipContents,
},
FunctionName: 'testFunction', /* required */
Role: 'arn:aws:iam::149727569662:role/ROLE', /* required */
Description: 'Created with tempalte',
Handler: 'index.handler',
MemorySize: 256,
Publish: true,
Runtime: 'nodejs12.x',
Timeout: 15,
TracingConfig: {
Mode: "Active"
}
};
lambda.createFunction(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
上面的代码给出了错误Could not unzip uploaded file. Please check your file, then try to upload again
如何读取 URL 文件?并将其传递给params
谁能帮帮我
【问题讨论】:
-
如果您阅读 CreateFunction 的文档,您会发现 ZipFile 是一个 blob,而不是 ZIP 文件的 URL。如果您使用
S3Key: zipContents代替ZipFile: zipContents,这是否有效?
标签: javascript node.js amazon-web-services file amazon-s3