aws lambda - POST url encoded form to Amazon API Gateway -
i'm creating webhook receive notifications 3rd-party service, sent data in body of post content type application/x-www-form-urlencoded
.
but generates same error:
{"message": "could not parse request body json: unrecognized token \'name\': expecting \'null\', \'true\', \'false\' or nan\n @ [source: [b@456fe137; line: 1, column: 6]"}
i reproduce error following curl call:
% curl -v -x post -d 'name=ignacio&city=tehuixtla' https://rl9b6lh8gk.execute-api.us-east-1.amazonaws.com/prod/mandrilllistener * trying 54.230.227.63... * connected rl9b6lh8gk.execute-api.us-east-1.amazonaws.com (54.230.227.63) port 443 (#0) * tls 1.2 connection using tls_ecdhe_rsa_with_aes_128_gcm_sha256 * server certificate: *.execute-api.us-east-1.amazonaws.com * server certificate: symantec class 3 secure server ca - g4 * server certificate: verisign class 3 public primary certification authority - g5 > post /prod/mandrilllistener http/1.1 > host: rl9b6lh8gk.execute-api.us-east-1.amazonaws.com > user-agent: curl/7.43.0 > accept: */* > content-length: 27 > content-type: application/x-www-form-urlencoded > * upload sent off: 27 out of 27 bytes < http/1.1 400 bad request < content-type: application/json < content-length: 180 < connection: keep-alive < date: thu, 28 jan 2016 12:29:40 gmt < x-amzn-requestid: cd4d9232-c5ba-11e5-a158-b9b39f0b0599 < x-cache: error cloudfront < via: 1.1 1915b8b49d2fbff532431a79650103eb.cloudfront.net (cloudfront) < x-amz-cf-id: cxu2_b5dziw4m_n3hjbfxtu9avrbl3gpbqquid9ixgs004dflyqymg== < * connection #0 host rl9b6lh8gk.execute-api.us-east-1.amazonaws.com left intact {"message": "could not parse request body json: unrecognized token \'name\': expecting \'null\', \'true\', \'false\' or nan\n @ [source: [b@d92973b; line: 1, column: 6]"}
if wrap body double-quotes works fine:
% curl -v -x post -d '"name=ignacio&city=tehuixtla"' https://rl9b6lh8gk.execute-api.us-east-1.amazonaws.com/prod/mandrilllistener * trying 54.230.227.19... * connected rl9b6lh8gk.execute-api.us-east-1.amazonaws.com (54.230.227.19) port 443 (#0) * tls 1.2 connection using tls_ecdhe_rsa_with_aes_128_gcm_sha256 * server certificate: *.execute-api.us-east-1.amazonaws.com * server certificate: symantec class 3 secure server ca - g4 * server certificate: verisign class 3 public primary certification authority - g5 > post /prod/mandrilllistener http/1.1 > host: rl9b6lh8gk.execute-api.us-east-1.amazonaws.com > user-agent: curl/7.43.0 > accept: */* > content-length: 29 > content-type: application/x-www-form-urlencoded > * upload sent off: 29 out of 29 bytes < http/1.1 200 ok < content-type: application/json < content-length: 6 < connection: keep-alive < date: thu, 28 jan 2016 12:33:20 gmt < x-amzn-requestid: 50610606-c5bb-11e5-b140-5d837ffe26ed < x-cache: miss cloudfront < via: 1.1 a670cda0e28541e40881b95b60c672b7.cloudfront.net (cloudfront) < x-amz-cf-id: mclkl4eonpumd15ixqzw0rstjhw9vdf3ivdcl37dcmno2jfofxw0vg== < * connection #0 host rl9b6lh8gk.execute-api.us-east-1.amazonaws.com left intact "true"%
the lamba has 1 line:
context.succeed('true');
how can make api gateway not treat body json?
i tried documentation template mapping no success, tried convert static template, no variables @ all! in cases error happens before getting code.
try set mapping template following:
{ "body" : $input.json('$') }
this convert string json , pass lambda.
from amazon docs: $input.json(x)
function evaluates jsonpath expression , returns results json string.
Comments
Post a Comment