Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway - How to create a post method and test it

My scenario is when my Lambda function's Api endpoint is hit, with a post variable, i want my Lambda to invoke a database connection and get some results.

So the first step is to create an API Gateway endpoint and I have problem creating the POST method with parameters

Here is what i did till now:

  1. Created a API Endpoint for my Lambda Function.

enter image description here

enter image description here

  1. When i go into the POST Method in Lambda's API endpoint section, i am taken to this screen

enter image description here

  1. When i Test the function from the AWS Console,

enter image description here

and response is as follows in the console

enter image description here

How do i create parameters for the api here? and how do i test it? I have my lambda function ready, that takes in a String as input and returns a String as response.

Can someone guide me for the next steps..

like image 932
Vamsi Challa Avatar asked May 26 '16 11:05

Vamsi Challa


People also ask

How do I add a method response to API gateway?

Set up method response status code For example, responses of 200, 400, and 500 indicate successful, client-side error and server-side error responses, respectively. To set up a method response status code, set the statusCode property to an HTTP status code.


2 Answers

You can check the Create and Test a POST Method

you do not mention the parameters in the lambda definition, the parameter will be taken from the request directly (so in future if you change your lambda code to take new parameters, you dont need to change the configuration

To test :

In the Method Execution pane, in the Client box, and then choose TEST.

Expand Request Body, and type the following:

{
  "name": "User" <or any other parameter that you expect>
}

Choose Test. If successful, Response Body will display the reply from your lambda execution

For example here an example post api I had

enter image description here

so again for POST API you dont define the parameters

If you were doing GET API you would define the query parameters

enter image description here

like image 182
Frederic Henri Avatar answered Sep 20 '22 13:09

Frederic Henri


Great step by step explanation of Serverless API on AWS: Serverless API on AWS in 10 minutes

enter image description here

like image 21
ybonda Avatar answered Sep 18 '22 13:09

ybonda