提问者:小点点

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


我有一个用例,我必须读取一个ZIP文件,并将其作为模板传递给lambda的创建。现在我想从一个S3公共桶中读取zip文件。如何从公共桶中读取文件?

我正在读取的S3 bucket 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
      });

上面的代码给出错误无法解压缩上载的文件。请检查您的文件,然后尝试重新上载

如何读取URL文件?并在参数中传递

这里有人能帮我吗


共1个答案

匿名用户

使用createFunction文档,特别是Code文档,您可以看到zipfile期望

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

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

文档中并不清楚是否允许使用公共桶来实现此目的,但文档中确实说过

AmazonS3 bucket位于与您的函数相同的AWS区域。桶可以在不同的AWS帐户中。