💠In this use case, we will see how to build REST API using AWS Lambda, API Gateway and store it in Dynamo DB, user test the same using POSTMAN tool
## Flow Diagram
📚Table of Content
📢-Creation of Dynamo DB table
📢-Creation of AWS Lambda Function
📢-Creation of API Gateway using REST API
📢-Test the REST API created using payload
🌍-Instructions to clean up AWS resource to avoid Billing
📢 ## Creation of Dynamo DB table
🎯 Go to AWS Management console, search for Dynamo DB. Click on create table as below
🎯Input the table name and partition key as below. Click create table
📢 ## Creation of AWS Lambda Function
📌Go to AWS Management console, search for AWS Lambda. Click on create a function
📌Give the function name as AddVehicle and runtime as Python3.10 and execution role as Create a new role with basic Lambda permissions. Click on Create function.
📌Go to Code source, add the below python code in the code editor.
import boto3
dynamodb=boto3.resource('dynamodb')
table=dynamodb.Table('vehicles')
def lambda_handler(event, context):
table.put_item(Item=event)
return { "statusCode": 200,"message": "vehicle is created successfully"}
📌 Successfully deploy the code by clicking on Deploy button
📢 ## Creation of API Gateway using REST API
🎈Go to AWS Management console, search for API Gateway. Go to REST API and click on build.
🎈Click on OK if the below pop-up appears
🎈Click on New-API, Give the API name and description as below and click Create API
🎈Go to Actions, Click on Create Resource as below
🎈Give the resource name and resource path, Click on create resource
🎈Go to Actions, Click on create method as below
🎈Give the method name as POST, integrate the lambda function (AddVehicle) which we already created in previous steps. Click on Save button
🌊Note*: Click on OK if below pop-up appears for API Gateway permission to invoke the lambda function
📢 ## Test the REST API created using payload
📍 It’s time to test the new API which has been created. Click on test in below screen which in turn will invoke your lambda function which will store the data created in Dynamo DB
📍 Give the payload as below in Request body. Click on Test
{
"vehicle_id":1,
"type":"scooter",
"availability":"true"
}
📍 If you face the below error, then it is due to AccessDeniedException. We have to create required IAM role for Lambda function
📍 Go to AWS Management console, search for AWS Lambda. Go inside your function, Click on configuration and navigate to permissions tab
📍 Go back to API Gateway and re-run your tests.
📍 Navigate to Dynamo DB and verify the new entries been created
📍 In order to access the API outside like Postman tool, we need to deploy our API as below
📍 Give the stage name where we need to deploy and click on Deploy button
💫Open the postman tool, copy the invoke URL and click on POST call as below
🌍Instructions to clean up AWS resource to avoid Billing
📌Delete the table created which is vehicle in our use case example. We need to delete the items created before deletion of table.
📌Delete the lambda function which has been created. In our use case it is AddVehicle.
📌Delete the API which has been created in API Gateway along with resource.
Thanks for being patient and followed me. Keep supporting 🙏
For more exercises — pls do follow me below ✅!
https://www.linkedin.com/in/vjraghavanv/
Top comments (0)