Deploying an API for an Amazon API Gateway

In the Amazon API Gateway, I created a simple API containing one resource named demo and one POST method corresponding to it:

enter image description here

Now I want my endpoint to accept the POST request of any Content-Type, so not necessarily application / json, but also plain / text. Then I want to take the request body and wrap it in a JSON object and send it to the Amazon Lambda function (Lambda functions can only accept a JSON object as a parameter).

For this purpose, I edited the integration request that matches my method to use custom pattern matching:

enter image description here

I used the link from the Amazon documentation that can be found here: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

My Lambda function looks like this:

exports.handler = function(event, context) {
    context.succeed(event);
};

When testing, I get the expected result no matter what I submit:

enter image description here

However, when I deploy, the conversion just doesn't work anymore, it expects JSON

  • Sending something does this:

enter image description here

  • Submitting JSON gives the following:

enter image description here

Is there any part of this process that was performed incorrectly? Am I losing something during deployment? To me this seems like a very annoying Amazon error, can anyone confirm this?

+4
source share
2 answers

Use the content type "application / json".

https://gist.github.com/maruks/e036168263cd412146e6

+3

Accept Content Type curl? , "text/plain" json

-H "Content-Type: text/plain" -H "Accept: application/json"
+1

Source: https://habr.com/ru/post/1598755/


All Articles