Serverless API with ReactJS
Let’s build a Serverless REST API for our ReactJS website!
In my last article, Deploy ReactJS App with S3 Static Hosting, we discussed hosting a simple React app on AWS with S3. This works great for simple static pages but what if you want to do something more? How do you host your API on S3? That is what we are discussing today how to integrate an API into our app to get or post information from our own database. We will be using Lambda, DynamoDB, and API gateway. So let’s get started.
Our app will be grabbing cards from our database and showing them to the user. How this works is when a user requests a card from our website, API Gateway, will invoke our Lambda function, that will get the details from our DynamoDB and show the details to the user! Simple enough.
Create an Amazon DynamoDB Table
Log into the AWS Console and use the search bar to navigate to the “DynamoDB” service.
Create a table
Click “Create table”.
Name it “MagicCards”. Enter “CardId” for the Partition key and select “String”.