amazon-dynamodb - AppSync BatchDeleteItem not executes properly
问题描述
I'm working on a React Native application with AppSync, and following is my schema to the problem:
type JoineeDeletedConnection {
items: [Joinee]
nextToken: String
}
type Mutation {
deleteJoinee(ids: [ID!]): [Joinee]
}
In 'request mapping template' to resolver to deleteJoinee
, I have following (following the tutorial from https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html):
#set($ids = [])
#foreach($id in ${ctx.args.ids})
#set($map = {})
$util.qr($map.put("id", $util.dynamodb.toString($id)))
$util.qr($ids.add($map))
#end
{
"version" : "2018-05-29",
"operation" : "BatchDeleteItem",
"tables" : {
"JoineesTable": $util.toJson($ids)
}
}
..and in 'response mapping template' to the resolver,
$util.toJson($ctx.result.data.JoineesTable)
The problem is, when I ran the query, I got empty result and nothing deleted to database as well:
// calling the query
mutation DeleteJoinee {
deleteJoinee(ids: ["xxxx", "xxxx"])
{
id
}
}
// returns
{
"data": {
"deleteJoinee": [
null
]
}
}
解决方案
I finally able to solve this puzzle, thanks to the answer mentioned here to point me to some direction.
Although, I noticed that JoineesTable does have trusted entity/role to the IAM 'Roles' section, yet it wasn't working for some reason. Looking into this more, I noticed that the existing policy had following actions
as default:
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem"
]
Once I added following two more actions
to the list, things have started working:
"dynamodb:BatchWriteItem",
"dynamodb:BatchGetItem"
Thanks to @Vasileios Lekakis and @Ionut Trestian on this appSync quest )
推荐阅读
- security - 使用频率分析/密码分析技术破解密文
- javascript - 创建一个允许任何键但具有已定义对象值的模式
- sql - 是否可以将聚合值提供给选择中的不同子查询
- elasticsearch - Logstash:使用 Filebeat 时如何从路径中获取字段?
- r - 解析数据框中的 json 列
- node.js - 有人可以创建“假”JWT 吗?
- javascript - 开关盒返回
- javascript - 带有 HTML 部分的 JQuery 切换
- python - 获取 Python 3.x 设置以在 Google Cloud 上使用
- r - 当我尝试将我的 r-markdown 导出为 pdf 时出现错误