AppSync BatchPutItem 不保存项目

Phi*_*ews 5 vtl amazon-web-services amazon-dynamodb graphql aws-appsync

我正在尝试使用 AppSync 将多个项目批量放入 DynamoDB。当我调用解析器时,它不会引发任何错误,但不会将任何内容保存到数据库中。

架构

type BoxScore @model {
  id: ID!
  userId: String!
  gameVariant: String!
  complete: Boolean!
  failFact: BoxScoreFact @connection
  totalCorrect: Int!
}

type BoxScoreFact @model {
  id: ID!
  left: Int!
  right: Int!
  gameVariant: String!
  timestamp: Int!
  correct: Boolean!
}

input BatchAddCreateBoxScoreFactInput {
  id: ID
  left: Int!
  right: Int!
  gameVariant: String!
  timestamp: Int!
  correct: Boolean!
  boxScoreFactBoxScoreId: ID!
}
Run Code Online (Sandbox Code Playgroud)

IAM 角色:

        "Effect": "Allow",
        "Action": [
            "dynamodb:DeleteItem",
            "dynamodb:GetItem",
            "dynamodb:PutItem",
            "dynamodb:Query",
            "dynamodb:Scan",
            "dynamodb:UpdateItem",
            "dynamodb:BatchGetItem",
            "dynamodb:BatchWriteItem"
        ],
Run Code Online (Sandbox Code Playgroud)

解析器

#set($factsdata = [])
#foreach($item in ${ctx.args.facts})
    $util.qr($factsdata.add($util.dynamodb.toMapValues($item)))
#end

{
    "version" : "2018-05-29",
    "operation" : "BatchPutItem",
    "tables" : {
        "TABLENAME": $utils.toJson($factsdata)
    }
}
Run Code Online (Sandbox Code Playgroud)

从 AppSync 游乐场调用:

在此处输入图片说明

响应映射模板:

  #if($ctx.error)
      ## Append a GraphQL error for that field in the GraphQL response
      $utils.error($ctx.error.message, $ctx.error.message)
  #end

  {
      "boxScoreFacts": $util.toJson({"res": "no error", "ctx": $ctx}),
  }
Run Code Online (Sandbox Code Playgroud)

功能测试运行的输出模板:

在此处输入图片说明

DynamoDB 表

在此处输入图片说明

其中TABLENAME设置为等于 DDB 控制台中显示的 DynamoDB 表名称。所以像 BoxScoreFact-woieieie99392-prod 这样的东西。

该表始终为空,响应为空。这几乎是直接从文档中的示例中提取的。另外,我应该注意,使用普通的 create graphql 函数放置一个项目确实将一个项目放到了预期的表中。

我在这里缺少什么?

小智 0

Appsync 的 lambda 函数是通过 Serverless Appsync 插件调用的,在此角色中,旧版本中缺少 BatchWriteItem。在 package.json 文件中尝试将插件版本更改为最新版本或修复了此问题的 GitHub 版本。

这应该可以修复它:

"devDependencies": {
   ....
   "serverless-appsync-plugin": "^1.1.0"
   ....
}
Run Code Online (Sandbox Code Playgroud)

或者

"devDependencies": {
   ....
   "serverless-appsync-plugin": "https://github.com/sid88in/serverless-appsync-plugin.git#e33b5cfd"
   ....
}
Run Code Online (Sandbox Code Playgroud)