簡體   English   中英

如何在沒有 Aws 密鑰和秘密的情況下從 S3 公共存儲桶讀取 zip 文件

[英]How to read zip file from S3 public bucket without Aws key and secret

我有一個用例,我必須讀取 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 Could not unzip uploaded file. Please check your file, then try to upload again

如何閱讀 URL 文件? 並在params中傳遞

有人能幫我一下嗎

使用createFunction 文檔,特別是Code 文檔,您可以看到ZipFile期望

部署 package 的 base64 編碼內容。 AWS SDK 和 AWS CLI 客戶端為您處理編碼。

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

從文檔中不清楚是否允許為此目的使用公共存儲桶,但文檔確實說

與您的 function 位於同一 AWS 區域的 Amazon S3 存儲桶。 存儲桶可以位於不同的 AWS 賬戶中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM