Search code examples
aws-api-gatewayamazon-kinesis-firehose

How to add a newline in a mapping template


seems trivial, but I can't get it to work: I'm sending data encoded as JSON objects to API Gateway which invokes Firehose. The resulting files in S3 contain all the JSON objects in a single line. I've read that it should be possible to add newlines, but whatever I try, there is either an error or it simply doesn't do anything. The mappping template looks like this

{
    "DeliveryStreamName": "file-datadump",
    "Record": { 
    "Data": "$util.base64Encode($input.json('$'))"
    }
}

Any ideas what to do?


Solution

  • The answer is ridiculously easy. Simply add a line break like so in the mapping template.

    #set($payload = "$input.json('$')
    ")
    {
       "DeliveryStreamName": "stream-name",
       "Record": { 
          "Data": "$util.base64Encode($payload)"
       }
    }