简体   繁体   English

为什么 aws lambda 函数无法从 s3 存储桶读取对象?

[英]Why aws lambda function is not able do read object from s3 bucket?

I am trying to read objects from S3 bucket using lambda function cross account, I have added resource based policy for aws lambda to access s3 bucket.我正在尝试使用 lambda 函数跨帐户从 S3 存储桶读取对象,我为 aws lambda 添加了基于资源的策略以访问 s3 存储桶。

But still when i tested my lambda function am seeing access denied error lambda function IAM role has the full access on s3 resources但是当我测试我的 lambda 函数时,我看到访问被拒绝错误 lambda 函数 IAM 角色拥有对 s3 资源的完全访问权限

Your situation appears to be:您的情况似乎是:

  • An AWS Lambda function in Account A that is using a Role账户 A 中使用角色的AWS Lambda 函数
  • An Amazon S3 bucket in Account B账户 B 中的Amazon S3 存储桶

You will need to grant access from Account B .您需要从帐户 B 授予访问权限 The Lambda resource policy will not work because it is in Account A (and therefore cannot grant access to resources in Account B). Lambda 资源策略将不起作用,因为它位于账户 A 中(因此无法授予对账户 B 中资源的访问权限)。

You simply need a Bucket Policy on the bucket that grants access to the Role being used by the Lambda function.您只需要一个存储桶上的存储桶策略,授予对 Lambda 函数使用的角色的访问权限。 The policy would look similar to:该政策将类似于:

{
  "Id": "Policy1",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "GrantAccessToRole",
      "Action": [
        "s3:GetObject"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::my-bucket/*",
      "Principal": {
        "AWS": [
          "arn:aws:iam::1234567890:role/my-role"
        ]
      }
    }
  ]
}

Modify the policy to provide the access permissions desired (eg ListBucket).修改策略以提供所需的访问权限(例如 ListBucket)。

The ARN for the role is visible in the IAM console when viewing the Role.查看角色时,该角色的 ARN 在 IAM 控制台中可见。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS lambda 无法访问跨账户 s3 存储桶 object 但从 cli 其工作 - AWS lambda not able to access cross account s3 bucket object but from cli its working 从 S3 存储桶导入 AWS Lambda 函数代码中的库 - Importing libraries in AWS Lambda function code from S3 bucket AWS Lambda function 未从 S3 存储桶事件触发器接收记录 object - AWS Lambda function not receiving Records object from S3 bucket event trigger 在AWS中如何使用lambda函数将文件从一个s3存储桶复制到另一个s3存储桶 - In AWS how to Copy file from one s3 bucket to another s3 bucket using lambda function AWS Lambda函数从S3读取并写入Elastic Cache - AWS Lambda function to read from S3 and write to Elastic Cache AWS Lambda:如何使用java从Lambda函数访问S3存储桶 - AWS Lambda : How to access S3 bucket from Lambda function using java AWS Lambda 使用 python 读取 S3 存储桶中的文件 - AWS Lambda read a file in the S3 bucket using python 如何从AWS Lambda函数返回存储在AWS S3存储桶上的HTML页面 - How to return HTML page stored on AWS S3 bucket from a AWS Lambda function AWS Lambda:如何读取 S3 存储桶中的 CSV 文件然后将其上传到另一个 S3 存储桶? - AWS Lambda: How to read CSV files in S3 bucket then upload it to another S3 bucket? AWS Lambda:使用Python从s3存储桶中读取csv文件尺寸,而无需使用Pandas或CSV包 - AWS Lambda: read csv file dimensions from an s3 bucket with Python without using Pandas or CSV package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM