简体   繁体   English

如何在没有 Aws 密钥和秘密的情况下从 S3 公共存储桶读取 zip 文件

[英]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 .相反,您需要使用S3BucketS3Key

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.

相关问题 AWS S3 Javascript SDK-使用浏览器中的密钥和机密从私有存储区下载文件 - AWS S3 Javascript SDK - download file from private bucket with key and secret in browser 在不暴露访问密钥的情况下将文件上传到非公共 S3 存储桶的最佳方式 - Best way to upload a file to a non-public S3 bucket without exposing access key 如何在不直接访问存储桶的情况下下载存储在 Amazon S3 上的资产(zip 文件) - How to download an asset (zip file) stored on Amazon S3 without having direct access to the bucket 以 Zip 文件的形式从 S3 存储桶下载多个文件 - Download multiple files from S3 bucket in the form of Zip file 如何将 Zip 文件从 s3 存储桶下载到 node.js lambda 函数中的本地目录 - How to download Zip File from an s3 bucket to a local directory within a node.js lambda function 我如何读取 EC2 实例文件夹中的 CSV 文件,而不是 AWS 中的 S3 存储桶? - How do I read an CSV file in an EC2 instance folder as oppose to an S3 bucket in AWS? 您可以在没有 AWS 登录凭证的情况下从 Amazon S3 存储桶下载文件吗 - Can you download a file from Amazon S3 bucket without having AWS login credentials 如何在AWS S3的存储桶参数中初始化密钥 - How to initialize the key in the bucket parameters for AWS S3 如何在AWS S3存储桶中使用相同的键删除多个对象 - How to delete multiple objects with the same key in aws s3 bucket 如何显示不公开的s3存储桶中的对象 - How to show objects from an s3 bucket that is not public
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM