Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AWS Appsync多表BatchPutItem返回Null_Amazon Web Services_Aws Appsync - Fatal编程技术网

Amazon web services AWS Appsync多表BatchPutItem返回Null

Amazon web services AWS Appsync多表BatchPutItem返回Null,amazon-web-services,aws-appsync,Amazon Web Services,Aws Appsync,我一直在学习批处理操作教程: 当我尝试执行多表批处理时,即使对象已成功提交到dynamodb,我也会得到一个空响应 这是我的变异: 读取数据{ 记录读数( 临时读物:[ {sensorId:1,值:85.5,时间戳:“2018-02-01T17:21:05.000+08:00”}, {sensorId:2,值:85.7,时间戳:“2018-02-01T17:21:06.000+08:00”}, {sensorId:3,值:85.8,时间戳:“2018-02-01T17:21:07.000+0

我一直在学习批处理操作教程:

当我尝试执行多表批处理时,即使对象已成功提交到dynamodb,我也会得到一个空响应

这是我的变异:

读取数据{
记录读数(
临时读物:[
{sensorId:1,值:85.5,时间戳:“2018-02-01T17:21:05.000+08:00”},
{sensorId:2,值:85.7,时间戳:“2018-02-01T17:21:06.000+08:00”},
{sensorId:3,值:85.8,时间戳:“2018-02-01T17:21:07.000+08:00”},
{sensorId:4,值:84.2,时间戳:“2018-02-01T17:21:08.000+08:00”},
{sensorId:5,值:81.5,时间戳:“2018-02-01T17:21:09.000+08:00”}
]
本地读数:[
{传感器ID:1,lat:47.615063,长:-122.333551,时间戳:“2018-02-01T17:21:05.000+08:00”},
{传感器ID:2,lat:47.615163,长:-122.333552,时间戳:“2018-02-01T17:21:06.000+08:00”}
{传感器ID:3,lat:47.615263,长:-122.333553,时间戳:“2018-02-01T17:21:07.000+08:00”}
{传感器ID:4,lat:47.615363,长:-122.333554,时间戳:“2018-02-01T17:21:08.000+08:00”}
{传感器ID:5,lat:47.615463,长:-122.333555,时间戳:“2018-02-01T17:21:09.000+08:00”}
]) {
位置读数{
传感器
时间戳
拉特
长的
}
温度测定{
传感器
时间戳
价值
}
}

}
感谢您提出的一个非常详细的问题,它确实帮助我调试了您的问题。因此,为了解决您的问题,您需要调整响应映射模板。我能够在没有回应的情况下重现这个问题。原因是多表批处理put响应的形状采用以下格式:

"result": {
    "data": {
        "TemperatureReadingTable": [
            {
                "value": 85.5,
                "sensorId": "1",
                "timestamp": "2018-02-01T17:21:05.000+08:00"
            },
            {
                "value": 85.7,
                "sensorId": "2",
                "timestamp": "2018-02-01T17:21:06.000+08:00"
            },
            {
                "value": 85.8,
                "sensorId": "3",
                "timestamp": "2018-02-01T17:21:07.000+08:00"
            },
            {
                "value": 84.2,
                "sensorId": "4",
                "timestamp": "2018-02-01T17:21:08.000+08:00"
            },
            {
                "value": 81.5,
                "sensorId": "5",
                "timestamp": "2018-02-01T17:21:09.000+08:00"
            }
        ],
        "LocationReadingTable": [
            {
                "lat": 47.615063,
                "long": -122.333551,
                "sensorId": "1",
                "timestamp": "2018-02-01T17:21:05.000+08:00"
            },
            {
                "lat": 47.615163,
                "long": -122.333552,
                "sensorId": "2",
                "timestamp": "2018-02-01T17:21:06.000+08:00"
            },
            {
                "lat": 47.615263,
                "long": -122.333553,
                "sensorId": "3",
                "timestamp": "2018-02-01T17:21:07.000+08:00"
            },
            {
                "lat": 47.615363,
                "long": -122.333554,
                "sensorId": "4",
                "timestamp": "2018-02-01T17:21:08.000+08:00"
            },
            {
                "lat": 47.615463,
                "long": -122.333555,
                "sensorId": "5",
                "timestamp": "2018-02-01T17:21:09.000+08:00"
            }
        ]
    },
因此,
$context.result.data
将返回一个对象,其字段为
TemperatureReadingTable
LocationReadingTable
。但是,您正在应用
$util.toJson
解析类型
RecordResult
,该类型的子字段为
temperatureReadings
locationReadings

请使用以下定义更新您的响应映射模板,它将适用于您:

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

  {
      "temperatureReadings": $util.toJson(${ctx.result.data.TemperatureReadingTable}),
      "locationReadings": $util.toJson(${ctx.result.data.LocationReadingTable})
  }
此外,我建议您从控制台的设置页面启用CloudWatch日志,并选择
ALL
。这将记录请求/响应头、已解决的请求/响应模板、跟踪信息等。因此,通过查看请求/响应模板的内容,它将帮助您快速识别此类问题


感谢您带来这个问题,如果文档中没有提到这一点,我们将更新文档。

嘿,只是仔细检查了文档,似乎是正确的。文档与示例的唯一区别在于示例中的数据源名称分别为
LocationReadingTable
TemperatureReadingTable
,而文档中的数据源名称分别为
locationReadings
temperatureReadings
。感谢您的回答!我确实检查了日志,但不幸的是,我没有弄清楚实现它的语法,所以这很有帮助。文档关闭,因为BatchPutItem的响应映射模板要求返回$utils.toJson($ctx.result.data),这将不起作用。这应该像你在上面所展示的那样。在修复文档的同时,还应该修复多表批处理下的示例。所有传感器ID都设置为“sensorId:1”,但由于传感器ID是主键,因此无法工作。