This guide explains how to deploy a React app using S3 for hosting, DynamoDB for database, and Lambda + API Gateway for backend API.
git clone <this-repo-url>
cd <project-folder>
npm install
npm start
Verify it runs successfully at http://localhost:3000
.
- Go to AWS Console → S3 → Create Bucket
- Enter a unique bucket name
- Unselect Block all public access
- Select I acknowledge... warning
- Click Create bucket
-
Open your bucket
-
Go to Properties
-
Scroll to Static website hosting → Enable
-
Enter:
- Index document:
index.html
- Index document:
-
Save changes
Build the React project:
npm run build
Sync build folder to S3: . make sure your terminal is at your current folder path
aws s3 sync build/ s3://<your-bucket-name>
-
Go to AWS Console → DynamoDB → Create table
-
Enter:
- Table name:
yourtable
- Partition key:
id
(Number)
- Table name:
-
After table creation → click Create item and paste:
{
"id": { "N": "102" },
"age": { "N": "100" },
"email": { "S": "yourname@example.com" },
"name": { "S": "My Name" },
"phone": { "N": "03001234567" },
"salary": { "N": "0" }
}
-
Go to AWS Console → Lambda → Create Function
-
Select:
- Runtime: Node.js
- Function name:
GetUsers
-
Paste code:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { ScanCommand, DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
const client = new DynamoDBClient({ region: "us-east-1" });
const docClient = DynamoDBDocumentClient.from(client);
const params = {
TableName: "yourtable"
};
async function getDynamoDBItem() {
try {
const data = await docClient.send(new ScanCommand(params));
return data;
} catch (error) {
console.log(error);
return error;
}
}
export const handler = async (event, context) => {
try {
const data = await getDynamoDBItem();
return { body: JSON.stringify(data) };
} catch (error) {
console.log(error);
return error;
}
};
- Deploy and Test the function.
- Go to API Gateway → Create API
- Create Resource and add Method → GET
- Attach your lambda function to api gateway.
- Enable CORS
- Deploy API → create a new stage
- Copy the Invoke URL
In your React project, update src/component/user
with the API_URL
from API Gateway.
npm run build
aws s3 sync build/ s3://<your-bucket-name>
- Go to S3 → Your Bucket → Properties
- Scroll to Static website hosting
- Copy the Bucket website endpoint
- Open it in your browser 🎉
You can check out the live app (hosted on AWS Free Tier) before it expires: