{"id":3157,"date":"2015-08-19T07:32:06","date_gmt":"2015-08-19T07:32:06","guid":{"rendered":"http:\/\/blog.cloudthat.com\/?p=3157"},"modified":"2024-06-25T11:13:41","modified_gmt":"2024-06-25T11:13:41","slug":"api-gateway-lambda-dynamodb","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/integrating-aws-api-gateway-lambda-and-dynamodb","title":{"rendered":"Integrating AWS API Gateway, Lambda and DynamoDB"},"content":{"rendered":"<p>In the current world of API, every mobile application and website have to communicate using dedicated API servers. These dedicated servers are explicitly set to handle the API calls for an application. API servers act as an intermediary between the application and the database. The bottleneck of this setup is that the API server has to be maintained to handle all the API calls. The increase in the number of API calls, increases the load of the API server which may require auto-scaling, which is cost-consuming.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3272 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1-e1439558955581.png\" alt=\"1\" width=\"435\" height=\"254\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The latest approach of the best architects is to utilize a new AWS service that explicitly replaces the need for a dedicated API Server. AWS API Gateway provides the ability to act as an interface between application and database which uses AWS Lambda function as the backend.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3273 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/2-e1439559012654.png\" alt=\"2\" width=\"460\" height=\"262\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>To get the essence of AWS API Gateway, we need to get hands-on with it. The next part of the blog is a detailed tutorial on how to use AWS API Gateway along with AWS Lambda &amp; DynamoDB.<\/p>\n<p>People who are familiar with DynamoDB, API Gateway and Lambda can proceed with the high-level instructions. Also for people who are new to these services, there are detailed instructions which can be followed for step-by-step guidance.<\/p>\n<p>The first step will be to create a DynamoDB table which stores the data. Next\u00a0a Lambda function which inserts the data into DynamoDB table. An\u00a0API Gateway is setup to trigger the Lambda function. Finally a REST Client will be used to call the API.<\/p>\n<h2><strong>Step 1: Create a DynamoDB table:<\/strong><\/h2>\n<h4><strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3278 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/3.png\" alt=\"3\" width=\"253\" height=\"134\" \/><\/a><\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">Create a DynamoDB table named <\/span><b>Employee<\/b><span style=\"font-weight: 400;\"> with the attributes of primary key as <\/span><b>emp_id<\/b><span style=\"font-weight: 400;\">. Accept the rest of attributes as default and review the table details.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>[showhide type=&#8221;dynamodb&#8221;\u00a0more_text=&#8221;For Detailed Instructions..&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<ol>\n<li>Go to <strong>console.aws.amazon.com<\/strong> and sign into your account. On the services dashboard select <strong>DynamoDB.<\/strong>\u00a0Click on <strong>Create Table<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3141 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db1.png\" alt=\"Create Table\" width=\"395\" height=\"303\" \/><\/a><\/li>\n<li>On the next screen\n<ul>\n<li>Enter <strong>Employee<\/strong> as the\u00a0<strong>Table Name<\/strong>.<\/li>\n<li>Select <strong>Primary Key<\/strong> Type as <strong>Hash<\/strong>.<\/li>\n<li>Provide the <strong>Hash attribute Name<\/strong>\u00a0(like an Primary key) as\u00a0<strong>emp_Id<\/strong> then click <strong>Continue.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3143 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db2.png\" alt=\"Table Detail\" width=\"595\" height=\"500\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li><strong>Skip<\/strong> the Global indexes settings on the next screen.<\/li>\n<li>On the Provision Throughput Capacity screen, leave the<strong>\u00a0read and write capacity<\/strong> as <strong>1<\/strong> then click <strong>Continue.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3148 size-medium\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db3.png\" alt=\"Provision Throughput\" width=\"300\" height=\"240\" \/><\/a><\/li>\n<li>Finally review the settings and click\u00a0<strong>Create<\/strong> table.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db5.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3160 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/db5.png\" alt=\"Review Table\" width=\"628\" height=\"421\" \/><\/a><\/li>\n<\/ol>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Step 2: Create a Lambda Function:<\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/test-prep-e1477043709154.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3296 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/test-prep-e1477043709154.png\" alt=\"4\" width=\"297\" height=\"105\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Create a node.js Lambda function called <\/span><b>addEmployee<\/b><span style=\"font-weight: 400;\">. Use code from the following location, <\/span><a href=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/cloudthatcode\/addEmployee.zip\"><span style=\"font-weight: 400;\">https:\/\/s3-ap-southeast-1.amazonaws.com\/cloudthatcode\/addEmployee.zip<\/span><\/a><span style=\"font-weight: 400;\">. Replace IAM access and secret keys of a user with access to write into the DynamoDB table.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>[showhide type=&#8221;lambda&#8221;\u00a0more_text=&#8221;For Detailed Instructions..&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<ol>\n<li>On the <strong>Lambda service page<\/strong>\u00a0click on\u00a0<strong>Get Started Now.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3161 size-medium\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm1.png\" alt=\"Lambda Getting Started\" width=\"300\" height=\"147\" \/><\/a><\/li>\n<li>On the next screen, click <strong>Skip.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3162 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm2.png\" alt=\"skip Blueprint\" width=\"905\" height=\"585\" \/><\/a><\/li>\n<li>On the next screen\n<ul>\n<li>Enter the name of the function as \u00a0<strong>addEmployee<\/strong>.<\/li>\n<li>Enter a description for the function.<\/li>\n<li>From the dropdown select the runtime as N<strong>ode.js<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3163 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm3.png\" alt=\"lm3\" width=\"706\" height=\"362\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Scroll down to the bottom of the screen and do the following\n<ul>\n<li>Select code entry type as <strong>Edit Code Inline.<\/strong><\/li>\n<li>Download the sample\u00a0code by visiting this URL\u00a0\u00a0<a href=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/cloudthatcode\/addEmployee.zip\">https:\/\/s3-ap-southeast-1.amazonaws.com\/cloudthatcode\/addEmployee.zip<\/a>.<\/li>\n<li>Paste the sample\u00a0code provided into the editor as shown below.<\/li>\n<li>Create a user in IAM with access to write into the DynamoDB table.<\/li>\n<li>Replace IAM access and secret keys of that user into the code and save.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm4.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3164 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm4.png\" alt=\"lm4\" width=\"933\" height=\"497\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Next scroll down further and on the following\n<ul>\n<li>Leave the handler as default.<\/li>\n<li>For IAM\u00a0Role, select\u00a0<strong>Create New IAM Role<\/strong>, select <strong>DynamoDb event stream Role<\/strong>, which will redirect you to the IAM Management Console.<\/li>\n<li>Enter the name as\u00a0<strong>dynamodb-Access <\/strong>and click<strong>\u00a0Allow.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm5.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3165 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm5.png\" alt=\"lm5\" width=\"799\" height=\"559\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Under <strong>Advanced settings<\/strong> leave everything as default and click <strong>Continue<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3166 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm6.png\" alt=\"lm6\" width=\"959\" height=\"413\" \/><\/a><\/li>\n<li>Finally review the function click <strong>Create function.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm7.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3167 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm7.png\" alt=\"lm7\" width=\"937\" height=\"497\" \/><\/a><\/li>\n<li>Now we will <strong>test<\/strong> the function.\n<ul>\n<li>Click on <strong>Test<\/strong> .<\/li>\n<li>Provide the <strong>parameters<\/strong> for the Lambda Function as given below and submit.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm9.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3169 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm9.png\" alt=\"lm9\" width=\"863\" height=\"634\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>\u00a0The\u00a0<strong>Execution result<\/strong>\u00a0 will show as succeeded and the record will be inserted in the Employee table.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm10.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3170 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/lm10.png\" alt=\"lm10\" width=\"353\" height=\"400\" \/><\/a><\/li>\n<\/ol>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Step 3: Create an API in API Gateway :<\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3313 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/6-e1439559092897.png\" alt=\"6\" width=\"447\" height=\"290\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Next create an API called <\/span><b>Employee_API,<\/b><span style=\"font-weight: 400;\">\u00a0a resource called <\/span><b>employee<\/b><span style=\"font-weight: 400;\"> and create a <\/span><b>POST <\/b><span style=\"font-weight: 400;\">Method. Use Lambda as the integration type and select the Lambda function you created earlier. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Test the API with the following values from the console. <\/span><\/p>\n<pre class=\"lang:default decode:true\">{\r\n\r\n\u201cemp_id\u201d : \u201c2\u201d\r\n\r\n\u201cemp_Name\u201d : \u201cSnow\u201d\r\n\r\n\u201cemp_Salary\u201d : \u201c200000\u201d\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">You should see the entries in the DynamoDB table.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For creating an API we need to create Resource, create POST method under the resource and utilize the Lambda function as integration type and the Deployment of API is up for launch.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>[showhide type=&#8221;apigateway&#8221;\u00a0more_text=&#8221;For Detailed Instructions..&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<p>For creating API we will Create Resource, create POST method under the resource and we will provide the Lambda function as integration type and then we will Deploy the API.<\/p>\n<ol>\n<li>Go to the <strong>API Gateway<\/strong> service page and click on <strong>Get Started.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3171 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag1.png\" alt=\"ag1\" width=\"804\" height=\"429\" \/><\/a><\/li>\n<li>Enter the <strong>API name<\/strong>\u00a0as\u00a0<strong>Employee_API<\/strong>.<\/li>\n<li>Provide a <strong>Description<\/strong> and <strong>Create API.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3172 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag2.png\" alt=\"ag2\" width=\"1069\" height=\"321\" \/><\/a><\/li>\n<li>On the top right of the screen click on <strong>Create Resource.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3173\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag3.png\" alt=\"ag3\" width=\"710\" height=\"159\" \/><\/a><\/li>\n<li>Provide the Resource Name as\u00a0<strong>employee <\/strong>and click<strong> Create Resource.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag4.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3174 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag4.png\" alt=\"ag4\" width=\"704\" height=\"425\" \/><\/a><\/li>\n<li>Click on\u00a0<strong>Create Method<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3175\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag5.png\" alt=\"ag5\" width=\"711\" height=\"129\" \/><\/a><\/li>\n<li>Select <strong>POST<\/strong> Method .<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3176 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag6.png\" alt=\"ag6\" width=\"753\" height=\"219\" \/><\/a><\/li>\n<li>Next do the following\n<ul>\n<li>Select <strong>Lambda Function<\/strong> as the<strong>\u00a0Integration type<\/strong>.<\/li>\n<li>Select the <strong>Lambda Region<\/strong> and the <strong>Lambda Function<\/strong> you created earlier.<\/li>\n<li>Click <strong>Save.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3360\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag7.png\" alt=\"ag7\" width=\"710\" height=\"368\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Grant the <strong>Permission<\/strong> changes for the API lambda function by clicking <strong>OK<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag8.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3178 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag8.png\" alt=\"ag8\" width=\"601\" height=\"234\" \/><\/a><\/li>\n<li>The API has been <strong>created<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag9.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3179 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag9.png\" alt=\"ag9\" width=\"708\" height=\"550\" \/><\/a><\/li>\n<li>Next\u00a0<strong>Test<\/strong> the API.<\/li>\n<li>Click on <strong>TEST\u00a0<\/strong>in the console as shown below.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag10.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3180 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag10.png\" alt=\"ag10\" width=\"977\" height=\"540\" \/><\/a><\/li>\n<li>Provide <strong>payload<\/strong> as given and click <strong>Test.<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag11.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3181 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag11.png\" alt=\"ag11\" width=\"984\" height=\"477\" \/><\/a><\/li>\n<li>You should will get a success response and check if the record\u00a0has been <strong>inserted<\/strong> into the table.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag12.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3182 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag12.png\" alt=\"ag12\" width=\"362\" height=\"197\" \/><\/a><\/li>\n<li>We will now\u00a0<strong>Deploy<\/strong> the API.<\/li>\n<li>Click on the <strong>Deploy API<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3183\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag13.png\" alt=\"ag13\" width=\"345\" height=\"163\" \/><\/a><\/li>\n<li>Next do the following\n<ul>\n<li>Select <strong>New Stage.<\/strong><\/li>\n<li>Provide <strong>Stage Name<\/strong> and <strong>Description <\/strong>and click<strong> Deploy<\/strong><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag141.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3184 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag141.png\" alt=\"ag14\" width=\"597\" height=\"400\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Once the Stage has been deployed and you will get the <strong>invoke URL<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag15.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3185 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag15.png\" alt=\"ag15\" width=\"985\" height=\"638\" \/><\/a><\/li>\n<\/ol>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Step 4: Call the API using REST Client<\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/7.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3316 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/7.png\" alt=\"7\" width=\"279\" height=\"186\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Test the API setup. For this Install a REST client. There are extensions for Mozilla firefox and Chrome which can be used which can be use to make REST calls. Install the one specific to your Browser. Invoke the API URL with the following values<\/span><\/p>\n<pre class=\"lang:default decode:true \">{\r\n\r\n\u201cemp_id\u201d : \u201c3\u201d\r\n\r\n\u201cemp_Name\u201d : \u201cJack\u201d\r\n\r\n\u201cemp_Salary\u201d : \u201c200000\u201d\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Check the DynamoDB table again for the entries.<\/span><\/p>\n<p style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The response from the DynamoDB is processed by the Lambda function and routed via the API Gateway. <\/span><\/p>\n<p>[showhide type=&#8221;restclient&#8221;\u00a0more_text=&#8221;For Detailed Instructions..&#8221; less_text=&#8221;Hide Details&#8221; hidden=&#8221;yes&#8221;]<\/p>\n<ol>\n<li>Install the REST client for Mozilla\/Chrome. Go to Add-ons\/extensions and search for <strong>RESTClient <\/strong>and <strong>Install.<\/strong><\/li>\n<li>Select the http <strong>POST<\/strong> Method<\/li>\n<li>Enter<strong>\u00a0<\/strong>the<strong> Invoke URL<\/strong>\u00a0as the <strong>URL.<\/strong> Add your <strong>Resource Name<\/strong>\u00a0i.e. employee to the end of the URL.<\/li>\n<li>Enter the <strong>Payload<\/strong> as provided.<\/li>\n<li>Send the <strong>Request<\/strong>.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag16.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3186 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag16.png\" alt=\"ag16\" width=\"972\" height=\"232\" \/><\/a><\/li>\n<li>You should see the a <strong>Successful<\/strong> response and the final employee entry added to the <strong>Employee<\/strong> table.<a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag17.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-3187 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/ag17.png\" alt=\"ag17\" width=\"602\" height=\"118\" \/><\/a><\/li>\n<\/ol>\n<p>[\/showhide]<\/p>\n<p>&nbsp;<\/p>\n<p>With minimal effort a REST API has been created which accepts data, \u00a0which in turn gets processed by Lambda function and finally stored in a DynamoDB table. This API is ready for use and can be used in any application.<\/p>\n<p>The API gateway frees the developer from maintaining infrastructure for APIs.\u00a0On the whole AWS API Gateway is a beneficial package for the developer. The API gateway provides nifty features where we can create different stages for development. It also has a useful testing platform which can be used to test the calls. It also provides caching and monitoring.<\/p>\n<p>In my next <strong><a title=\"Deep dive into the AWS API Gateway\" href=\"https:\/\/blog.cloudthat.com\/deep-dive-into-the-aws-api-gateway\/\">blog <\/a><\/strong>I have talked about securing your API&#8217;s in API gateway, passing Query string &amp; headers, transforming response type and returning the custom error code.The hands on is included. 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 or you can also ask the questions to <a style=\"color: #20629b;\" href=\"https:\/\/forum.cloudthat.com\/\" rel=\"nofollow\">https:\/\/forum.cloudthat.com<\/a><\/p>\n<p>Thank you.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/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\/3157"}],"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=3157"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/3157\/revisions"}],"predecessor-version":[{"id":41145,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/3157\/revisions\/41145"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=3157"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=3157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}