AccessDeniedException:用户无权对资源执行 dynamodb BatchWriteItem:table

AccessDeniedException: User is not authorized to perform dynamodb BatchWriteItem on resource: table

我正在使用 nodejs、无服务器和 aws dynamodb。我正在尝试创建一个 lambda,我在其中调用 API,获取数据(1000 条记录),现在,我想将这些数据插入到我的 dynamodb 中。

我正在为此使用 batchWrite,并通过创建 25 个 json 个对象的桶来使用它。但我收到一个错误:
AccessDeniedException: <Username> is not authorized to perform dynamodb BatchWriteItem on resource <table-name>

当我在没有 batchWrite 和单独的 PUT 操作的情况下执行相同操作时,它工作正常(但我需要使用批处理,因为这会导致吞吐量超出错误)。

我已将 AWS 中的所有管理权限授予我使用无服务器的用户。

在您的 serverless.yml 文件中,您应该添加一个新角色

    - Effect: Allow
  Action:
    - dynamodb:DescribeTable
    - dynamodb:Query
    - dynamodb:Scan
    - dynamodb:GetItem
    - dynamodb:PutItem
    - dynamodb:UpdateItem
    - dynamodb:DeleteItem
    - dynamodb:BatchWriteItem
  Resource: "arn:aws:dynamodb:${self:custom.region}:*:table/*"

以下是我在使用 Amplify CLI 项目时的设置方式:

{
    "Effect": "Allow",
    "Action": [
        "dynamodb:PutItem",
        "dynamodb:DeleteItem",
        "dynamodb:GetItem",
        "dynamodb:Query",
        "dynamodb:Scan",
        "dynamodb:UpdateItem",
        "dynamodb:BatchWriteItem",
        "dynamodb:Scan"
    ],
    "Resource": "arn:aws:dynamodb:*:*:table/*"
},
{
    "Effect": "Allow",
    "Action": "dynamodb:Query",
    "Resource": "arn:aws:dynamodb:*:*:table/*/index/*"
}