amazon-web-services - AWS IAM - 从 Lambda 到 DynamoDB 的访问被拒绝

标签 amazon-web-services aws-lambda amazon-dynamodb url-shortener iaas

我正在关注这个tutorial from Medium.com使用 AWS 创建 URL 缩短器。

我已经设置了全部内容,但在进行第一次测试时,我在尝试从 Lambda 获取 DynamoDB 项目时遇到权限错误。

如教程中所述,Lambda 在某个角色下运行。该角色已附加下一项政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "dynamodb:PutItem",
                "dynamodb:DeleteItem",
                "dynamodb:GetItem",
                "dynamodb:Query",
                "dynamodb:UpdateItem"
            ],
            "Resource": "arn:aws:dynamodb:eu-west-3:922842442607:table/lambda-dynamodb-url-shortener"
        }
    ]
}

但是,正如我之前所说,我收到此错误:

[ERROR] ClientError: An error occurred (AccessDeniedException) when calling the GetItem operation: User: arn:aws:sts::***:assumed-role/lambda-dynamodb-url-shortener-role/url-shortener-create is not authorized to perform: dynamodb:GetItem on resource: arn:aws:dynamodb:eu-west-3:***:table/url-shortener-table

当我检查 IAM 策略模拟器时,我可以看到该角色具有上述策略:

enter image description here

但是,正如预期的错误一样,我在尝试使用以下角色模拟对 DynamoDB 的访问时收到此错误:

enter image description here

有什么线索吗? :(

最佳答案

您的政策与实际资源不匹配。您在策略中引用了 table/lambda-dynamodb-url-shortener,但错误消息提到了 table/url-shortener-table。因此,您需要更改策略以允许访问 table/url-shortener-table 或修复 lambda 代码以实际与名为 lambda-dynamodb-url-shortener< 的 dynamodb 表进行通信。 (可能第一个解决了问题)

关于amazon-web-services - AWS IAM - 从 Lambda 到 DynamoDB 的访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72160726/

相关文章:

node.js - 在nodejs中,我可以有子文件夹,每个子文件夹都托管一个AWS lambda函数吗?

arrays - 在 AWS dynamoDB 中更新 JSON 数组

python - 将现有 Python 应用程序导入 AWS Lambda

amazon-web-services - 在 elasticbeanstalk 上部署私有(private) github repo golang 应用程序

amazon-web-services - 如何正确设置Kibana的Filebeat和Metricbeat?

amazon-web-services - 将IAM组添加到AWS EKS中的aws-auth配置映射

elasticsearch - 使用 JestClient 用 java 编写的 lambda 函数对 AWS Elasticsearch 的第一次查询的响应非常慢

aws-lambda - 一个或多个参数值无效: Type mismatch for key xyz expected: S actual: M

node.js - 这种情况下如何进行容量控制呢?

java - 输入和输出流的 IOUtils.copy() 速度非常慢