简体   繁体   English

使用Dynamo Db在AWS Appsync中执行批处理获取故障

[英]Trouble Executing Batch Get in AWS Appsync with Dynamo Db

I have trouble executing Batch Get in app sync. 我在执行批处理获取应用同步时遇到问题。 This is my following resolvers. 这是我的以下解析器。

Request mapping template. 请求映射模板。

#set($ids = [])
#foreach($id in ${ctx.args.topicIds})
   #set($map = {})
   $util.qr($map.put("topicId", $util.dynamodb.toString($id)))
   $util.qr($ids.add($map))
#end

{
 "version" : "2018-05-29",
 "operation" : "BatchGetItem",
 "tables" : {
    "Topic": {
        "keys": $util.toJson($ids),
        "consistentRead": true
    }
 }
}

Response Mapping Template 响应映射模板

$util.toJson($ctx.result.data.Topic)

This is how I give the query 这就是我给查询的方式

 query listStudentBookmarkedTopics {
   listStudentBookmarkedTopics(
     topicIds: [ "503", "501" ]
   ) {
     topicId
   }
 }

But I am getting null results 但我得到空结果

 {
  "data": {
    "listStudentBookmarkedTopics": [
      null,
      null
    ] 
  }
}

This is how my table looks like 这是我的桌子的样子

在此处输入图片说明

This is Cloud watch logs 这是云监视日志

在此处输入图片说明

what does your DynamoDB Table look like? 您的DynamoDB表是什么样的? Is Topic the name of the table? 表格的名称是Topic吗? What is the primary partition key defined on it? 在上面定义的主分区键是什么? I need additional details to help you with this. 我需要其他详细信息来帮助您。

Alternatively, please turn on CloudWatch logs for your API (you should be able to do this via Console -> under Settings page for your API). 或者,请为您的API打开CloudWatch日志(您应该可以通过API的“设置”页面下的控制台->执行此操作)。 Try to run your query again, and see what is the resolved Request and Response templates for this path. 尝试再次运行查询,然后查看此路径解析的“请求和响应”模板。 That should provide you additional details. 那应该为您提供更多详细信息。

I had a similar problem. 我有一个类似的问题。 Fixed it by applying appropriate permissions. 通过应用适当的权限对其进行了修复。 If you created new IAM role it doesn't grant batch* permissions by default. 如果创建了新的IAM角色,则默认情况下它不会授予batch*权限。 From AWS docs: 从AWS文档中:

Like other resolvers, you need to create a data source in AWS AppSync and either create a role or use an existing one. 与其他解析器一样,您需要在AWS AppSync中创建一个数据源,然后创建一个角色或使用一个现有角色。 Because batch operations require different permissions on DynamoDB tables, you need to grant the configured role permissions for read or write actions: 由于批处理操作在DynamoDB表上需要不同的权限,因此您需要为配置的角色授予读取或写入操作的权限:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "dynamodb:BatchGetItem",
        "dynamodb:BatchWriteItem"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:dynamodb:region:account:table/TABLENAME",
        "arn:aws:dynamodb:region:account:table/TABLENAME/*"
      ]
    }
  ]
}

You either can attach a new policy or just add "dynamodb:BatchGetItem" on existing one in IAM dashboard. 您可以附加一项新策略,也可以仅在IAM仪表板中的现有策略上添加"dynamodb:BatchGetItem" ` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM