无法从Lambda函数访问S3存储桶

时间:2015-09-16 02:38:32

标签: amazon-web-services amazon-s3 lambda

我创建了一个简单的Lambda函数,它接收一个文件作为Base64字符串并将其上传到我的S3存储桶。我使用了Lambda控制台建议的默认S3角色:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:*:*:*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Resource": [
        "arn:aws:s3:::*"
      ]
    }
  ]
}

但我仍然遇到访问错误:

{
  "errorMessage": "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.",
  "errorType": "PermanentRedirect",
  "stackTrace": [

"arn:aws:s3:::*"不能满足我的所有需求吗?我还需要添加什么才能使用此功能?

2 个答案:

答案 0 :(得分:4)

must be addressed using the specified endpoint错误通常表示存储区域与您使用代码调用的端点之间不匹配。

例如:AWS客户端连接与Sydney建立,但存储桶位于东京。

尝试这样的事情:

var s3 = new AWS.S3({region: 'ap-southeast-2'});

答案 1 :(得分:0)

您的sourceKey设置也可能发生这种情况,尝试在S3中添加确切的文件路径,如:

{
  "Records": [
    {
      "eventVersion": "2.0",
      "eventTime": "1970-01-01T00:00:00.000Z",
      "requestParameters": {
        "sourceIPAddress": "127.0.0.1"
      },
      "s3": {
        "configurationId": "testConfigRule",
        "object": {
          "eTag": "0123456789abcdef0123456789abcdef",
          "sequencer": "0A1B2C3D4E5F678901",
          "key": "images/HappyFace.jpg",
          "size": 1024
        },
        "bucket": {
          "arn": "arn:aws:s3:::mybucket",
          "name": "mybucket",
          "ownerIdentity": {
            "principalId": "EXAMPLE"
          }
        },
        "s3SchemaVersion": "1.0"
      },
      "responseElements": {
        "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
        "x-amz-request-id": "EXAMPLE123456789"
      },
      "awsRegion": "us-east-1",
      "eventName": "ObjectCreated:Put",
      "userIdentity": {
        "principalId": "EXAMPLE"
      },
      "eventSource": "aws:s3"
    }
  ]
}
相关问题