1

My body mapping is defined as:

{
    "csv": "$input.body",
    "p1": false,
    "p2": "p3",
    "p3": "p4"
}

Invoking the function with

curl 'https://xxxxx.execute-api.us-west-2.amazonaws.com/prod/xxx?p3=aaa&p4=bbb' \
-XPOST -H "Content-Type: application/csv"  -d @input.csv

Where input.csv contains

l1c1,l1c2
l2c1,l2c2
l3c1,l3c2

Will end up with calling my lambda function with

{
    "csv": "l1c1,l1c2l2c1,l2c2l3c1,l3c2",
    "p1": false,
    "p2": "p3",
    "p3": "p4"
}

Is there a way NOT to remove the newlines from the body? $input.body should evaluate to the "RAW PAYLOAD" according to the docs here http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#d0e9653

Also tried using $util.escapeJavaScript($input.body), but it does not make any difference at all.

Decoding $util.base64Encode($input.body) also has the newlines stripped...

Thanks,

Ákos Vandra-Meyer
  • 1,890
  • 1
  • 23
  • 40

2 Answers2

3

Turns out --data or -d sends the data as www-form-urlencoded, thus strips out new lines. --data-binary is the correct way to send the file in my case.

Ákos Vandra-Meyer
  • 1,890
  • 1
  • 23
  • 40
0

From curl's man page:

Posting data from a file named 'foobar' would thus be done with --data @foobar. When --data is told to read from a file like that, carriage returns and newlines will be stripped out.

See also: How to send line break with curl?

Community
  • 1
  • 1
Lorenzo d
  • 2,016
  • 10
  • 17