【问题标题】:AWS API Gateway & Kinesis Firehose Integration: Adding Additonal dataAWS API Gateway 和 Kinesis Firehose 集成:添加其他数据
【发布时间】:2017-03-11 14:47:39
【问题描述】:

我目前正在使用以下映射模板将发送到 AWS API Gateway 端点的数据传递到 AWS Kinesis Firehose 流:

{
    "DeliveryStreamName": "[STREAMNAME]",
    "Record": {
        "Data": "$util.base64Encode($input.body)"
    }
}

我想做的是:向$input.body 添加信息,该信息被编码为发出请求的客户端的$context.identity.sourceIp

当传递给 Kinesis Firehose 的输出需要进行 Base64 编码时,我该如何处理?理想情况下,我希望发布到 Kinesis Firehose 的数据如下所示:

{
  "x": 1,
  "y": 2,
  "z": 3,
  ...,                   // all the properties from the JSON-request by the client
  "clientIp": "x.x.x.x"  // property added by API-Gateway into client's object
}

【问题讨论】:

    标签: base64 aws-api-gateway amazon-kinesis-firehose


    【解决方案1】:

    经过更多的挖掘,我设法让以下工作:

    #set($inputRoot = $input.path('$'))
    #set($data =  "{
      #foreach($key in $inputRoot.keySet())
      ""$key"": $input.json($key),
      #end
      ""clientIP"": ""$context.identity.sourceIp"",
    }")
    {
        "DeliveryStreamName": "[STREAMNAME]",
        "Record": {
            "Data": "$util.base64Encode($data)"
        }
    }
    

    我不知道您可以在#set 中执行#foreach。请注意,您还必须使用双引号才能做到这一点。

    【讨论】:

    • 感谢关于#set #foreach 上的双引号的说明。我在 cloudwatch 中收到了非常无用的错误消息。
    猜你喜欢
    • 2016-01-14
    • 2019-09-29
    • 2019-12-19
    • 1970-01-01
    • 2020-12-29
    • 2016-03-16
    • 2017-05-24
    • 2016-11-13
    相关资源
    最近更新 更多