In this post, I will show you how to build a in following the approach using , & . RESTful API Node.JS Serverless AWS Lambda API Gateway DynamoDB Serverless computing is a cloud computing execution model in which the cloud provider dynamically manages the allocation of machine resources All the code is available on my Github 1 — API Specification The will expose endpoints to manage a store of movies. The operations that our endpoints will allow are: REST API service 2 — DynamoDB Table Go to , then click on “ ” button, and fill the table name and set a primary key: DynamoDB Console Create table 3 — Write a new Movie Lambda Function The code is self explanatory, I have used the method to insert a new movie item and library to generate a random unique id for the movie item: put uuid Go to the and create a new function as below: Lambda Dashboard Add the table name as an and update the name to the function name in the code above: DynamoDB environment variable handler Note: you should use a with permission to access & . IAM Role DynamoDB Lambda Once created, you can click on “ ” and send a JSON as below: Test The item has been successfuly inserted into : DynamoDB 4 — List all Movies Lambda Function The code is self explanatory, I used method to fetch all items from the table: scan Fill the function configuration as below: Similar to the write function, we need to add table name as an : DynamoDB environment variable Once created, you could test the function by clicking on the “ ” button: Test Congratulation ! We have successfuly created our : Lambda functions 5 — Setup API Gateway Go to and create a new API. API Gateway Console 5.1 — GET /movies 5.2 — POST /movies Once done, deploy the API: Copy down the : API Invoke URL 6 — Test Let’s test it out: 6.1 — Create a Movie With Postman: With : cURL |curl -sSX POST -d ‘{“name”:”Gladiator”}’ https://3z0neyn1nf.execute-api.us-east-1.amazonaws.com/prod/movies 6.2 — List Movies With : Postman With : cURL |curl -sSX GET https://3z0neyn1nf.execute-api.us-east 1.amazonaws.com/prod/movies If we check our DynamoDB Table
Share Your Thoughts