Hello All,
I saw many forums on this topic, but all the information is in bits and pieces and mainly in Node JS (not in Java). This blog will illustrate the steps in very simple manner and with a video of each step in Java.
Problem Statement : In the REST call ( made using AWS ), you want to fetch a query string from URL and do some action based on it. Your application type accepts JSON input.
Prerequisite : You should have the knowledge of how to link API gateway and Lambda ( In case you need a tutorial for that, please contact me or leave a comment )
This tutorial example is illustrates delete an employee with an employee ID in the query string param e.g. /deleteemployee?id=5
Steps to do
Step 1 : Implement request stream handler : In order to have more control in your function, Implement Request stream handler as in the video below. Then parse the input as JSON object.
Please check the video now for Step 1.
Step 2 : Implement the request mapping to accept Query string parameter and in the integration request set the mapping template as JSON and define the template body as pass through (this will ensure that you get all data in JSON format as in the pass through template) .
Please check the video below now for Step 2.
Step 3 : This is the final step to assist you in completion. Test the API Gateway and enter the Query String value( please ignore the username and password in the video for now, as it is for basic authorization. You can use if you need, but not mandatory for this tutorial).
Once you test, you will see the JSON format in API gateway log.
Using the same structure to get the query string in your Java code as in the video below.
Enjoy and do not forget to leave a comment.
I saw many forums on this topic, but all the information is in bits and pieces and mainly in Node JS (not in Java). This blog will illustrate the steps in very simple manner and with a video of each step in Java.
Problem Statement : In the REST call ( made using AWS ), you want to fetch a query string from URL and do some action based on it. Your application type accepts JSON input.
Prerequisite : You should have the knowledge of how to link API gateway and Lambda ( In case you need a tutorial for that, please contact me or leave a comment )
This tutorial example is illustrates delete an employee with an employee ID in the query string param e.g. /deleteemployee?id=5
Steps to do
Step 1 : Implement request stream handler : In order to have more control in your function, Implement Request stream handler as in the video below. Then parse the input as JSON object.
Please check the video now for Step 1.
Step 2 : Implement the request mapping to accept Query string parameter and in the integration request set the mapping template as JSON and define the template body as pass through (this will ensure that you get all data in JSON format as in the pass through template) .
Please check the video below now for Step 2.
Step 3 : This is the final step to assist you in completion. Test the API Gateway and enter the Query String value( please ignore the username and password in the video for now, as it is for basic authorization. You can use if you need, but not mandatory for this tutorial).
Once you test, you will see the JSON format in API gateway log.
Using the same structure to get the query string in your Java code as in the video below.
Enjoy and do not forget to leave a comment.
Comments
Post a Comment