【问题标题】:How to read zip file from S3 public bucket without Aws key and secret如何在没有 Aws 密钥和秘密的情况下从 S3 公共存储桶读取 zip 文件
【发布时间】: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


【解决方案1】:

使用createFunction docs,特别是Code docs,您可以看到ZipFile 期望

部署包的 base64 编码内容。 AWS SDK 和 AWS CLI 客户端为您处理编码。

而不是它所在位置的 URL。相反,您需要使用S3BucketS3Key

从文档中不清楚是否允许公共存储桶用于此目的,但文档确实说

与您的函数位于同一 AWS 区域的 Amazon S3 存储桶。存储桶可以位于不同的 AWS 账户中。

【讨论】:

    猜你喜欢
    • 2022-08-05
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    相关资源
    最近更新 更多