Creating a RESTFul API using AWS Lambda, DynamoDB and API Gateway with Serverless architecture

One of the most interesting concepts that I have been introduced to is Serverless architecture. It offers many benefits including no server management, flexibility to scale, built-in availability and fault tolerance. 

In the example below I have used REST API service to manage items.

Creating a DynamoDB table for storing the items.

Manually inserting record into the items table.

Created a Lambda function which used scan method to fetch all records from the items table using NodeJs runtime.

The TABLE_NAME was configured as an Environment Variable. A test event was run and results were as expected.

The put method was used to insert records into the items table.

The uuid library was used to ensure that a unique itemid was generated with every insert. Another test event was created to test the Lambda function. The itemid was not mentioned as I wanted it to be autogenerated.

Successful testing of the Lambda function

Now I can check back on the DynamoDB items table and I can see the new record inserted with the unique itemid.

Finally I have created API using API Gateway. I have created GET and POST methods which will be using the Lambda Function as the integration type.

After creating the methods I moved to deploying the newly created API which generated the Invoke URL.

Using Postman I tested the API.

First I added an item.

Then I listed all the items from the items table.


To view or add a comment, sign in

More articles by Saad Shujaat Kanwar

Insights from the community

Others also viewed

Explore topics