Every mobile app and website must communicate with dedicated API servers in the modern world of API. These servers are specifically set up to handle API calls for applications. The API servers act as an intermediary for the application and the database. This setup has a major problem: the API server must be maintained in order to process all API calls. The API server may be overwhelmed by the increasing number of API calls. This can lead to costly auto-scaling.
The latest approach taken by the best architects is to use a new AWS service which replaces the need to have an API Server. AWS API Gateway acts as an interface between the application and the database, using AWS Lambda as the backend.
We need to get our hands-on experience with AWS API Gateway in order to understand its essence. The blog’s next section will provide a detailed tutorial on AWS API Gateway, DynamoDB, and AWS Lambda.
The high-level instructions are available for those who are familiar with DynamoDB API Gateway, Lambda and Lambda. These instructions can also be used to guide people who are unfamiliar with these services.
First, create a DynamoDB database table to store the data. Next, a Lambda function will insert the data into DynamoDB tables. To trigger the Lambda function, an API Gateway will be created. Finally, the API will be called by a REST Client.
Step 1: Create a DynamoDB Table
Create a DynamoDB database table called Employee with the attributes emp_id as primary key. Accept the default attributes and review the details of the table.
For more information.
Go to console.aws.amazon.com and sign into your account. Select DynamoDB from the services dashboard. Click on Create Table.
Next screen: Enter Employee as the Table name.
Select Primary Key Type for Hash.
Click Continue to enter the Hash attribute Name (like a Primary key) and click on emp_Id.
Skip to the next screen for Global indexes settings.
Click Continue on the Provision Throughput Capacity screen.
Finalize the settings and click on Create table.
Step 2: Create a Lambda Function
Create a node.js Lambda Function called addEmployee. Use code from the following location, https://s3-ap-southeast-1.amazonaws.com/cloudthatcode/addEmployee.zip. Replace IAM access and secret key of a user with access that allows them to write into the DynamoDB database table.
For more information.
Click on the Get Started Now button on the Lambda page.
Next screen, click Skip.
Next screen: Enter the name of the function in the addEmployee box.
Please enter a description of the function.
Select Node.js from the dropdown.
Scroll to the bottom of your screen and do the following: Select code entry type as Edit code Inline
Download the sample code by visiting this URL https://s3-ap-southeast-1.amazonaws.com/cloudthatcode/addEmployee.zip.
Copy the code from the sample file into the editor, as shown below.
Create an IAM user with write access to the DynamoDB table.
Save by replacing IAM access with secret keys for that user in the code.
Scroll down and click the nextLeave handler as default.
Select Create New IAM role, then select DynamoDb Event stream Role. This will redirect you to IAM Management Console.
Enter the name dynamodb Access and click Allow.
Click Continue in Advanced Settings to leave everything as it is and click on Continue.
Final review the function and click Create function.
Now, we’ll test the function. Click on Test.
Please enter the parameters of the Lambda Function below and click submit.
The Execution result will indicate that the execution was successful and the record will then be inserted into the Employee table.
Step 3: Create an API using API Gateway
Next, create an API called Employee_API and a resource called employee. Finally, create a POST method. Use Lambda for the integration type