[英]How to read zip file from S3 public bucket without Aws key and secret
I have a use case where I have to read a ZIP file and pass it to the creation of lambda as a template.我有一个用例,我必须读取 ZIP 文件并将其传递给 lambda 作为模板的创建。 Now I want to read zip file from a S3 public bucket.
现在我想从 S3 公共存储桶中读取 zip 文件。 How can I read the file from the public bucket?
如何从公共存储桶中读取文件?
S3 bucket zip file where I am reading is https://lambda-template-code.s3.amazonaws.com/LambdaTemplate.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
});
The above code gives error Could not unzip uploaded file. Please check your file, then try to upload again
上面的代码给出错误
Could not unzip uploaded file. Please check your file, then try to upload again
Could not unzip uploaded file. Please check your file, then try to upload again
How can I read the URL file?如何阅读 URL 文件? And pass it in the
params
并在
params
中传递
Can anyone help me here有人能帮我一下吗
Using the createFunction docs and specifically the Code docs , you can see that ZipFile
expects使用createFunction 文档,特别是Code 文档,您可以看到
ZipFile
期望
The base64-encoded contents of the deployment package.
部署 package 的 base64 编码内容。 AWS SDK and AWS CLI clients handle the encoding for you.
AWS SDK 和 AWS CLI 客户端为您处理编码。
and not a URL of where it is.而不是它所在的 URL。 Instead, you need to use
S3Bucket
and S3Key
.相反,您需要使用
S3Bucket
和S3Key
。
It is not clear from the docs that public buckets are allowed for this purpose, but the docs do say从文档中不清楚是否允许为此目的使用公共存储桶,但文档确实说
An Amazon S3 bucket in the same AWS Region as your function.
与您的 function 位于同一 AWS 区域的 Amazon S3 存储桶。 The bucket can be in a different AWS account.
存储桶可以位于不同的 AWS 账户中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.