Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 834
DrGonzoX Avatar asked Oct 29 '25 07:10

DrGonzoX


2 Answers

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)"
   }
}
like image 75
DrGonzoX Avatar answered Nov 01 '25 07:11

DrGonzoX


NO LONGER CURRENT! - DO NOT USE

I was having the exact same issue. As per this helpful git issue, you can hack around it by appending a base64 encoded newline, example:

{
    "DeliveryStreamName": "$stageVariables.delivery_stream",
    "Record": {
        "Data":"$util.base64Encode($input.params().querystring)Cg=="
    }
}

It's not ideal, but hope that helps!

like image 29
rjmurt Avatar answered Nov 01 '25 07:11

rjmurt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!