将 api 网关连接到运动流

connect api gateway to kinesis stream

我已将 API 网关配置为 Kinesis 代理,如亚马逊将记录放入 Kinesis 流的教程中所述。

集成请求的 HTTP headers 是:

content-type application/json 的 body 映射模板如下所示:

#set($event =  "{
  ""rows"": ""$input.json('$')"",
 ""uuid"": ""$input.params('uuid')"",
}")
{
   "StreamName": "$input.params('stream-name')",  
   "Data": "$util.base64Encode($event)",  
   "PartitionKey": "$input.params('$partition-key')"
}

我在发送 post 请求时收到内部服务器错误。

您的 body 模板映射似乎有问题。

如果 "PartitionKey" 是请求 body 的一部分,请使用 $input.path('$.PartitionKey') ,例如当您的请求 body 是 {"Data" : "example-data", "PartitionKey" : "example-key"}

;如果 "partition-key" 是 api 路径(或查询字符串,或 header)的一部分,则使用 $input.params('partition-key') 例如当您的 url 是abc.api-xxxxx.com/{stream-name}/{parition-key}/{uuid}.

有关输入变量的更多帮助,请参阅 http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference

谢谢!