【问题标题】:API gateway and DynamoDB integration - SerializationExceptionAPI 网关和 DynamoDB 集成 - SerializationException
【发布时间】:2020-10-15 17:12:27
【问题描述】:

我已将 API 端点集成到 DynamoDB。 我想使用查询字符串参数作为查询过滤器来查询表。 不幸的是,我最终得到了错误:

Method response body after transformations: {"__type":"com.amazon.coral.service#SerializationException"}

不知道根本原因是什么。

为了完成上述操作,我采取了以下步骤:

1) 在 API 网关中设置 get 方法

2) 在方法请求中,我在 URL 查询字符串参数中添加了一个参数

3) 在集成请求中,我在 URL 查询字符串参数中添加了步骤 2 中的相同参数

4)在 DynamoDB 表中,我为要查询的列贴了一个新索引

5)在body mapping模板中:

{
    "TableName": "tjusers",
    "IndexName" "badge-index",
    "KeyConditionExpression": "badge = :v1",
    "ExpressionAttributeValues": {
        ":v1": {
            "S": "$input.params('badge')"
        }
    }
}

例外:

xecution log for request f0081606-b521-11e8-adb2-cd8092221b33
Mon Sep 10 17:50:00 UTC 2018 : Starting execution for request: f0081606-b521-11e8-adb2-cd8092221b33
Mon Sep 10 17:50:00 UTC 2018 : HTTP Method: GET, Resource Path: /db/users
Mon Sep 10 17:50:00 UTC 2018 : Method request path: {}
Mon Sep 10 17:50:00 UTC 2018 : Method request query string: {badge=18323}
Mon Sep 10 17:50:00 UTC 2018 : Method request headers: {}
Mon Sep 10 17:50:00 UTC 2018 : Method request body before transformations: 
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request URI: https://dynamodb.us-west-2.amazonaws.com/?Action=Query&badge=11111
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request headers: {Authorization=****************************************************************************************************************************************************************************************************************************************************************************************feb2ac, X-Amz-Date=20180910T175000Z, x-amzn-apigateway-api-id=53zgcztitj, Accept=application/json, User-Agent=AmazonAPIGateway_53zgcztitj, X-Amz-Security-Token=AgoGb3JpZ2l....
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request body after transformations: {
    "TableName": "tjusers",
    "IndexName" "badge-index",
    "KeyConditionExpression": "badge = :v1",
    "ExpressionAttributeValues": {
        ":v1": {
            "S": "11111"
        }
    }
}

Mon Sep 10 17:50:00 UTC 2018 : Sending request to https://dynamodb.us-west-2.amazonaws.com/?Action=Query&badge=18323
Mon Sep 10 17:50:00 UTC 2018 : Received response. Integration latency: 11 ms
Mon Sep 10 17:50:00 UTC 2018 : Endpoint response body before transformations: {"__type":"com.amazon.coral.service#SerializationException"}
Mon Sep 10 17:50:00 UTC 2018 : Endpoint response headers: {Server=Server, Date=Mon, 10 Sep 2018 17:49:59 GMT, Content-Type=application/x-amz-json-1.0, Content-Length=60, Connection=keep-alive, x-amzn-RequestId=ODMJ814D1GBN875T6MTR7BUHGVVV4KQNSO5AEMVJF66Q9ASUAAJG, x-amz-crc32=3948637019}
Mon Sep 10 17:50:00 UTC 2018 : Method response body after transformations: {"__type":"com.amazon.coral.service#SerializationException"}
Mon Sep 10 17:50:00 UTC 2018 : Method response headers: {X-Amzn-Trace-Id=Root=1-5b96aec8-addec09261723342f53a179f, Content-Type=application/json}
Mon Sep 10 17:50:00 UTC 2018 : Successfully completed execution
Mon Sep 10 17:50:00 UTC 2018 : Method completed with status: 200

【问题讨论】:

  • 迭代您的故障排除以涉及[暂时]不使用索引或 URL 查询字符串可能会有所帮助,以减少此处的一些变量。

标签: amazon-web-services amazon-dynamodb aws-api-gateway


【解决方案1】:

您在“IndexName”之后缺少 :,这会导致 SerializationException

【讨论】:

    【解决方案2】:

    您的tjusers DynamoDB 表的架构是什么? 特别是badge 的数据类型是什么?例如,如果是数字,则需要使用"N" 而不是"S"

    (总的来说,这是一个最近的新教程,它满足您的要求,并且比我在其他人看到的更多细节/屏幕截图:https://medium.com/@likhita507/using-api-gateway-to-get-data-from-dynamo-db-using-without-using-aws-lambda-e51434a4f5a0

    【讨论】:

      猜你喜欢
      • 2020-09-30
      • 2023-03-08
      • 1970-01-01
      • 2018-07-14
      • 2021-12-05
      • 2019-12-05
      • 2021-06-17
      • 1970-01-01
      • 2020-05-01
      相关资源
      最近更新 更多