Access denied on aws lambda function when getObject from S3 bucket

前端 未结 2 1320
逝去的感伤
逝去的感伤 2020-12-18 15:48

I\'m using the default code for a lambda function:

console.log(\'Loading function\');

var aws = require(\'aws-sdk\');
var s3 = new aws.S3({ apiVersion: \'20         


        
相关标签:
2条回答
  • 2020-12-18 16:27

    Check the IAM permissions of the role you want to use, maybe there are deny permissions above allow permissions.

    0 讨论(0)
  • 2020-12-18 16:28

    Looking at your log output, I can see that the key variable contains the following string:

    {\"originalFilename\":\"c12eaadf3d3b46d9b5ded6c078534c11\",\"versions\":[{\"Size\":1024,\"Crop\":null,\"Max\":false,\"Rotate\":0}]}
    

    I'm guessing you intended that variable to contain the string "c12eaadf3d3b46d9b5ded6c078534c11".

    S3 will return a 403 error response if you don't have access, or if the key doesn't exist. Returning "access denied" in both cases is a security feature to prevent attackers from finding out what keys actually exist in your bucket.

    I think you need to change this line:

    decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
    

    to something like this:

    decodeURIComponent(event.Records[0].s3.object.key.originalFilename.replace(/\+/g, ' '));
    
    0 讨论(0)
提交回复
热议问题