I am using AWS lambda as a proxy for my ElasticSearch service. I am facing issues with proxying requests to Multi search API. As this end point accepts payload in the form of ndjson, I am trying to send the following payload as request body and Content-Type as application/x-ndjson
. I tried different content-types but no use.
{"preference":"SearchResult"}\n
{"query":{"match_all":{}},"size":5,"from":0}
This request fails with a JSON syntax error.
{
"errorType": "SyntaxError",
"errorMessage": "Unexpected token \\ in JSON at position 29",
"trace": [
"SyntaxError: Unexpected token \\ in JSON at position 29",
" at JSON.parse (<anonymous>)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:67:14)"
]
}
This error is expected as lambda is trying to parse the request as JSON. So obviously the call is not reaching the Lambda handler function. How can I make Lambda function to work with ndjson? Is it possible?