gpt4 book ai didi

amazon-web-services - AppSync BatchPutItem 不保存项目

转载 作者:行者123 更新时间:2023-12-01 21:49:33 27 4
gpt4 key购买 nike

我正在尝试使用 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!
}

IAM 角色:

        "Effect": "Allow",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem",
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem"
],

解析器:

#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)
}
}

从 AppSync Playground 调用:

enter image description here

响应映射模板:

  #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}),
}

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

enter image description here

DynamoDB 表

enter image description here

其中 TABLENAME 设置为等于 DDB 控制台中显示的 DynamoDB 表名称。比如 BoxScoreFact-woieieie99392-prod。

表始终为空,响应为空。这几乎是直接从 example from the docs 中提取出来的。 。另外,我应该注意,使用正常的 create graphql 函数放置一个项目确实会将一个项目放入预期的表中。

我在这里缺少什么?

最佳答案

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

这应该可以修复它:

"devDependencies": {
....
"serverless-appsync-plugin": "^1.1.0"
....
}

"devDependencies": {
....
"serverless-appsync-plugin": "https://github.com/sid88in/serverless-appsync-plugin.git#e33b5cfd"
....
}

关于amazon-web-services - AppSync BatchPutItem 不保存项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57650203/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com