{"id":3596,"date":"2015-10-21T07:35:00","date_gmt":"2015-10-21T07:35:00","guid":{"rendered":"http:\/\/blog.cloudthat.com\/?p=3596"},"modified":"2024-06-25T11:13:17","modified_gmt":"2024-06-25T11:13:17","slug":"deep-dive-into-the-aws-api-gateway","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/deep-dive-into-the-aws-api-gateway","title":{"rendered":"Deep dive into the AWS API Gateway"},"content":{"rendered":"<p>From my previous <a title=\"Integrating AWS API Gateway, Lambda and DynamoDB\" href=\"https:\/\/blog.cloudthat.com\/api-gateway-lambda-dynamodb\/\" target=\"_blank\" rel=\"noopener\"><strong>blog<\/strong><\/a>, you can get a hands on with the AWS API Gateway. Now we will deep dive into it. Following points will be covered.<\/p>\n<ol>\n<li>How to pass <strong>Query String<\/strong> to the\u00a0method?<\/li>\n<li>How to pass <strong>Headers<\/strong> to the\u00a0method?<\/li>\n<li>How to <strong>Transform the Response<\/strong> of\u00a0the Method?<\/li>\n<li>How to receive <strong>Custom Response Code<\/strong> (400,500,\u2026) for the method?<\/li>\n<li>How partially secure your API using<strong> API Keys<\/strong><\/li>\n<\/ol>\n<h3><span style=\"text-decoration: underline;\"><strong>Prerequisites:<\/strong><\/span><\/h3>\n<ol>\n<li>Create a lambda function with code given\u00a0<a title=\"Code relating to product API for the Lambda Function\" href=\"https:\/\/s3-us-west-2.amazonaws.com\/cloudthat.training\/Lambda_S3_Route53_Lab\/DemoCode.rtf\" target=\"_blank\" rel=\"noopener\"><strong>here<\/strong><\/a><\/li>\n<li>Create and Deploy the Product API with\u00a0the GET Method, which integrates with the above function<\/li>\n<\/ol>\n<p>You can refer my previous <strong><a title=\"Integrating AWS API Gateway, Lambda and DynamoDB\" href=\"https:\/\/blog.cloudthat.com\/api-gateway-lambda-dynamodb\/\" target=\"_blank\" rel=\"noopener\">blog <\/a><\/strong>to have the prerequisites.<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>1.How to pass Query String to the method?<\/strong><\/h2>\n<p>You have an API with you already, where you are calling an API with GET method, you get\u00a0all the records in response, but what if we want a specific record in response? How can we get it? In this scenario, we can use the <strong>Query String<\/strong>. We will get the query string parameter from the HTTP request and then integrate the request using Mapping Templates.<\/p>\n<h4><strong>Step by Step process to pass the Query String Parameters\u00a0to the Method<\/strong><\/h4>\n<p>[showhide type=&#8221;qs&#8221;\u00a0more_text=&#8221;click here for Detailed Instructions..\u00a0&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Step 1: <\/strong>Go to your method, you will see\u00a0the below screen, click on\u00a0<strong>Integration R<\/strong><b>equest.<\/b><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/16.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3642\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/16.png\" alt=\"16\" width=\"626\" height=\"340\" \/><\/a><\/p>\n<p><strong>Step 2:<\/strong>\u00a0You will see the following screen<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/60.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3644\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/60.png\" alt=\"60\" width=\"985\" height=\"471\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong>\u00a0Click on <strong>Mapping Templates<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3645\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/17.png\" alt=\"17\" width=\"631\" height=\"297\" \/><\/a><\/p>\n<p><strong>Step 4:<\/strong> Click on <strong>Add mapping templates<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3646\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/18.png\" alt=\"18\" width=\"430\" height=\"162\" \/><\/a><\/p>\n<p><strong>Step 5<\/strong>: Write &#8220;<strong>text\/plain&#8221;<\/strong> and click on the <strong>tick<\/strong> to save<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/19.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3647\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/19.png\" alt=\"19\" width=\"433\" height=\"187\" \/><\/a><\/p>\n<p><strong>Step 6:<\/strong> Click on<strong> pencil symbol<\/strong> near Input passthrough and select <strong>Mapping Template<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 7:<\/strong> Enter following JSON string<\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"prod_Id\" : \"$input.params('prod_Id')\"\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Study-Guide-for-AZ-120.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3648\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Study-Guide-for-AZ-120.png\" alt=\"20\" width=\"624\" height=\"153\" \/><\/a><\/p>\n<p><strong>Step 8<\/strong>: Save the Template by clicking on the\u00a0<strong>tick<\/strong>.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/21.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3649\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/21.png\" alt=\"21\" width=\"625\" height=\"137\" \/><\/a><\/p>\n<p><strong>Step 9:<\/strong> Your API will accept the query string and it will be mapped as per our code.<\/p>\n<p><strong>Step 10<\/strong>: You can <strong>TEST<\/strong> your API using\u00a0<strong>REST Client. <\/strong>Call your API passing query string.<\/p>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2>2.How to pass Headers to the\u00a0method?<\/h2>\n<p>[showhide type=&#8221;header&#8221;\u00a0more_text=&#8221;click here for Detailed Instructions..\u00a0&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<p><strong>Step 1: <\/strong>Go to the\u00a0<strong>Method\u00a0Request<\/strong> and Click on the\u00a0<strong>HTTP Request Headers<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1115.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3652\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1115.png\" alt=\"5\" width=\"996\" height=\"446\" \/><\/a><\/p>\n<p><strong>Step 2:<\/strong> Click on the\u00a0<strong>Add Header<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/5-Tech-areas-that-are-changed-forever-after-AWS-reInvent-20161.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3653\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/5-Tech-areas-that-are-changed-forever-after-AWS-reInvent-20161.png\" alt=\"6\" width=\"997\" height=\"173\" \/><\/a><\/p>\n<p><strong>Step 3:<\/strong> Enter <strong>Name<\/strong> of the Header parameter<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/71.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3654\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/71.png\" alt=\"7\" width=\"992\" height=\"157\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong>\u00a0Navigate back to the Method Execution Console and click on<strong>\u00a0Integration Request<\/strong><\/p>\n<p><strong>Step 5<\/strong>: Click on<strong>\u00a0<\/strong>the<strong> Mapping Templates<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3645\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/17.png\" alt=\"17\" width=\"631\" height=\"297\" \/><\/a><\/p>\n<p><strong>Step 6<\/strong>: Click on the <strong>Add mapping <\/strong><b>templates<\/b><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3646\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/18.png\" alt=\"18\" width=\"430\" height=\"162\" \/><\/a><\/p>\n<p><strong>Step 7<\/strong>: Write &#8220;<strong>application\/json&#8221;<\/strong>\u00a0explicitly.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Screenshot-from-2016-08-18-20-34-28.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3655\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Screenshot-from-2016-08-18-20-34-28.png\" alt=\"8\" width=\"435\" height=\"186\" \/><\/a><\/p>\n<p><strong>Step 8<\/strong>: Click on <strong>Input passthrough<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/789.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3656\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/789.png\" alt=\"9\" width=\"1004\" height=\"187\" \/><\/a><\/p>\n<p><strong>Step 9:<\/strong> Enter the following JSON string<\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"prod_Id\" : \"$input.params('prod_Id')\"\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 10:<\/strong> <strong>Save<\/strong> the Template<\/p>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>3.How to Transform the Response of the method?<\/strong><\/h2>\n<p>Converting the response helps when\u00a0we are returning in JSON,\u00a0but\u00a0we need the output in XML. We can achieve the same by\u00a0transforming the API response. For transforming the response, we will again use mapping templates. We will write a template which converts the response and gives the desired type in return.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Step by Step process for transforming the JSON response to XML<\/strong><\/h4>\n<p>[showhide type=&#8221;trans&#8221;\u00a0more_text=&#8221;click here for Detailed Instructions..\u00a0&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<p><strong>Step 1:<\/strong> Go to <strong>Integration Response<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1200x628_June_29.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3659\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1200x628_June_29.png\" alt=\"29\" width=\"624\" height=\"391\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong>\u00a0Expand the integration\u00a0response as shown below<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/30.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3660\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/30.png\" alt=\"30\" width=\"632\" height=\"79\" \/><\/a><\/p>\n<p><strong>Step 3:<\/strong> Click on add <strong>Mapping templates<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/31.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3661\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/31.png\" alt=\"31\" width=\"620\" height=\"257\" \/><\/a><\/p>\n<p><strong>Step 4:<\/strong>\u00a0Click on add Mapping templates<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/32.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3662\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/32.png\" alt=\"32\" width=\"406\" height=\"175\" \/><\/a><\/p>\n<p><strong>Step 5:<\/strong>\u00a0Enter &#8220;<strong>application\/json&#8221;<\/strong> and click on tick to save it<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3663\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/10.png\" alt=\"10\" width=\"399\" height=\"191\" \/><\/a><\/p>\n<p><strong>Step 5:<\/strong>\u00a0Click on pencil icon to edit the select Mapping Template.Enter\u00a0the following Code and save<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">#set ($response = $input.path('$'))\r\n&lt;response&gt;\r\n    &lt;prod_Id&gt;$response.productDetails.prod_Id&lt;\/prod_Id&gt;\r\n    &lt;prod_Name&gt;$response.productDetails.prod_Name&lt;\/prod_Name&gt;\r\n    &lt;prod_Price&gt;$response.productDetails.prod_Price&lt;\/prod_Price&gt;\r\n&lt;\/response&gt;\r\n<\/pre>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/233.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3664\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/233.png\" alt=\"33\" width=\"561\" height=\"214\" \/><\/a><\/p>\n<p><strong>Step 6:<\/strong>\u00a0Navigate back to the Method Execution console\u00a0and click on <strong>Method Response<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/34.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3665\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/34.png\" alt=\"34\" width=\"627\" height=\"306\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 7:<\/strong>\u00a0Expand the Method response and \u00a0click on a pencil Icon as shown\u00a0below<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/35.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3666\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/35.png\" alt=\"35\" width=\"626\" height=\"81\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/36.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3667\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/36.png\" alt=\"36\" width=\"618\" height=\"158\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 8:<\/strong> Replace \u201cjson\u201d with \u201cxml\u201d and save<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/37.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3668\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/37.png\" alt=\"37\" width=\"621\" height=\"165\" \/><\/a><\/p>\n<p><strong>Note: Again deploy your API to test your API from REST Client.<\/strong><\/p>\n<p><strong>Step 9:<\/strong> Test the API from the REST\u00a0client<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/38.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3669\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/38.png\" alt=\"38\" width=\"625\" height=\"143\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>You will find the following response. Now check the <strong>Content-type<\/strong> in response.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/39.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3670\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/39.png\" alt=\"39\" width=\"582\" height=\"304\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>4.How to receive custom response code (400, 500,&#8230;) for the method?<\/strong><\/h2>\n<p>When we are calling any method, by default it returns 200 as a response code in AWS API Gateway. Even though if the response is success or error still the code returned will be 200. AWS\u00a0API Gateway provides the feature where we can actually give the custom code for the response.<\/p>\n<p>We have an API where we are passing a query string or header values like 1, 2 and 3. In response, we are getting the product detail about the respective product_Id. So we will set the custom code for the BAD REQUEST. If the person is passing the query string value more than 3, we will return an error with the custom code 400.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Step by Step process to Receive Custom Response Code from the Method<\/strong><\/h4>\n<p>[showhide type=&#8221;code&#8221;\u00a0more_text=&#8221;click here for Detailed Instructions..\u00a0&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Step 1:<\/strong> On your Method screen click on <strong>Method Response.<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/34.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3665\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/34.png\" alt=\"34\" width=\"627\" height=\"306\" \/><\/a><\/p>\n<p><strong>Step 2:<\/strong> Click on A<strong>dd Response<\/strong>.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/111.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3672\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/111.png\" alt=\"11\" width=\"609\" height=\"187\" \/><\/a><\/p>\n<p><strong>Step 3:<\/strong> Select the response code <strong>400<\/strong> and click on the tick to save.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1312.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3673\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1312.png\" alt=\"12\" width=\"686\" height=\"304\" \/><\/a><\/p>\n<p><strong>Step 4:<\/strong> Click on <strong>Integration Response<\/strong> and<strong> add an integration response<\/strong>.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1200x628_June_29.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3659\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1200x628_June_29.png\" alt=\"29\" width=\"624\" height=\"391\" \/><\/a><\/p>\n<p><strong>Step 5:<\/strong> Provide Lambda Error Regex as &#8220;<strong>Bad Request: .*&#8221;<\/strong>. For Method Response, select the Method response status as the code that you have inserted and click on save.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1200x628_CloudThat_13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3674\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1200x628_CloudThat_13.png\" alt=\"13\" width=\"985\" height=\"225\" \/><\/a><\/p>\n<p><strong>Step 6:<\/strong> Now click on an arrow button as shown below and click on mapping templates and add a template.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3675\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/14.png\" alt=\"14\" width=\"996\" height=\"202\" \/><\/a><\/p>\n<p><strong>Step 7:<\/strong> Provide \u201c<strong>application\/json<\/strong>\u201d as a content type and provide following string as a template and save.<\/p>\n<pre class=\"lang:default decode:true\">{\r\n        \u201cerrorMessage\u201d: \"Bad Request: You submitted invalid input\"\r\n}<\/pre>\n<p><strong>Step 8:<\/strong>\u00a0Enter\u00a0the below code in your <strong>lambda function<\/strong>\u00a0before the for loop<\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"prod_Id\" : \"$input.params('prod_Id')\"\r\n}<\/pre>\n<p><strong>Step 9:<\/strong> Test your function with the value greater than 3.<\/p>\n<p>&nbsp;<\/p>\n<p>It will return you custom code with our custom error.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1115.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3676\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1115.png\" alt=\"15\" width=\"1203\" height=\"280\" \/><\/a><\/p>\n<p><strong>\u00a0<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/5-Tech-areas-that-are-changed-forever-after-AWS-reInvent-20161.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3677\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/5-Tech-areas-that-are-changed-forever-after-AWS-reInvent-20161.png\" alt=\"16\" width=\"871\" height=\"435\" \/><\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>5.How partially secure your API using\u00a0API Keys<\/strong><\/h2>\n<p>API keys are key generated by the Developer. Developer\u00a0distributes the key to the third party users to restrict the unwanted user partially as well as to monitoring the API usage of the particular user. I have said that the API key is for the used for the authentication partially because AWS does not recommend to use only API Keys for the authentication.<\/p>\n<p>When we\u00a0enable the API Keys, the user must pass the Key to call the API. Othervise it will give retuen a message\u00a0<span class=\"JSON_parser_punctuation\" style=\"color: #000000;\"><strong>&#8220;Not able to access resources&#8221;<\/strong>.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h4><strong>Step by Step process to call the API using API Key<\/strong><\/h4>\n<p>[showhide type=&#8221;key&#8221;\u00a0more_text=&#8221;click here for Detailed Instructions..\u00a0&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<p>Step 1: In AWS API Gateway Menu bar click on <strong>APIs<\/strong> and select <strong>API Keys<\/strong><\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture171.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3713\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture171.png\" alt=\"17\" width=\"533\" height=\"235\" \/><\/a><\/p>\n<p>Step 2: Click on Create API Key<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/181.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3714\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/181.png\" alt=\"18\" width=\"346\" height=\"100\" \/><\/a><\/p>\n<p>Step 3: Provide and description, leave the check-box unchecked and save<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/191.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3715\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/191.png\" alt=\"19\" width=\"972\" height=\"226\" \/><\/a><\/p>\n<p>Step 4: Your API key has been generated, select API and Stage and click on Add.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/201.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3716\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/201.png\" alt=\"20\" width=\"976\" height=\"236\" \/><\/a><\/p>\n<p>Step 5: You can see your stage\u00a0has been added to the<strong>\u00a0<\/strong>Stages Enabled.<\/p>\n<p>Step 6: Now\u00a0navigate to the API Method Execution Console.<\/p>\n<p>Step 7: Click on Method Response<\/p>\n<p>Step 8: Make API Key Required as true<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/211.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3717\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/211.png\" alt=\"21\" width=\"789\" height=\"204\" \/><\/a><\/p>\n<p>Step 9: Now you can call API from the REST client it will give you message that &#8220;Not able to access resource&#8221;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/322.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3718\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/322.png\" alt=\"22\" width=\"351\" height=\"165\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Step 10: Now provide API key in headers of the API call as shown below<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/23.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3719\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/23.png\" alt=\"23\" width=\"1196\" height=\"269\" \/><\/a><\/p>\n<p>Step 11: You will get the proper response<\/p>\n<p><strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/24.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3720\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/24.png\" alt=\"24\" width=\"289\" height=\"159\" \/><\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<p>AWS API Gateway provides the service which provides the platform to create REST APIs with minimal efforts.it does not only provides the API calls as well as such a useful features as passing query string and header parameters, transforming the response type, returning the custom error code and using the API Keys for authentication.<\/p>\n<p>The\u00a0AWS API is becoming the powerful tool to create and deploy the REST APIs with integrating with Lambda function, although you can use the other endpoints as well.It also provides many other features like Cloud watch Monitoring,caching.API Key to distribute to the third party users.<\/p>\n<p>If you have any queries on API gateway or you have trouble getting it setup, feel free to drop a question into the comment section below.<\/p>\n","protected":false},"author":219,"featured_media":0,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3804,3606,3607,3665],"user_email":"prarthitm@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/3596"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/219"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=3596"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/3596\/revisions"}],"predecessor-version":[{"id":42350,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/3596\/revisions\/42350"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=3596"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=3596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}