Deploy Your React Website using AWS S3 and CloudFront
Debashis Badajena
MERN stack developer || Automation testing || Docker || Ci/Cd || AWS
?? How to Deploy Your React Website (The Fun Way!)
Hey there, React enthusiasts! ?? Ready to take your awesome React app from your local machine to the big, beautiful internet? Let's walk through a step-by-step guide filled with emotions, a touch of fun, and some ?? emojis!
We'll be creating a React app with Vite and TypeScript, deploying it to an Amazon S3 bucket, and making it super-fast using AWS CloudFront. ??? Buckle up, because this is going to be fun!
1. Build Your React App with Vite and TypeScript ??
Vite is like the Ferrari of build tools ???—super fast and sleek. And when you mix it with TypeScript, it’s like adding a nitro boost to your development process! ??
Steps to Get Started:
- Spin up your React project ???: Open your terminal (or your "command wizardry portal") and run:
npm create vite@latest my-react-app --template react-ts
cd my-react-app
npm install
- Fire up the dev server ??: Let’s see your app in action! Run:
npm dev
- Build it for production ???: When you’re ready to show the world, build your app with:
npm build
2. Deploy Your App to Amazon S3 ??
Amazon S3 is like a cosy home for your static website ??—safe, secure, and always ready to welcome visitors.
Steps to Deploy:
- Create a bucket (your app's home) ??:
- Head to the AWS Management Console.
- Navigate to S3 and click Create Bucket.
- Give it a cool name (like my-awesome-app) and choose your region.
Upload your app files ??:
Drag and drop the files from the dist folder into your S3 bucket. Feeling fancy? Use this CLI command:
aws s3 sync dist/ s3://your-bucket-name --acl public-read
- Enable static website hosting ??:
- Go to your bucket settings and enable Static Website Hosting.
- Set index.html as your default document.
?? Your app is live on S3! ??
领英推è
3. Add a Dash of Magic with AWS CloudFront ?
CloudFront is like sprinkling pixie dust on your app —it makes your website super-fast and globally available! ??
Steps to Set Up CloudFront:
Create a distribution ??:
- Go to CloudFront in AWS.
- Create a new distribution and select your S3 bucket as the origin.
Tweak the settings ??:
- Set caching rules to make your app snappy. ?
- Enable HTTPS because your app deserves to be secure. ??
Update the bucket policy ??: Ensure CloudFront has permission to access your S3 bucket. Use this JSON policy:
{
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
{
"Sid": "AllowCloudFrontServicePrincipal",
"Effect": "Allow",
"Principal": {
"Service": "cloudfront.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::your-account- id:distribution/distribution-id"
}
}
}
]
}
- Launch your app ??: Note the CloudFront domain (something like d232whjcxj3k.cloudfront.net) and share it with your friends. ??
Tools You'll Need ???
- Vite: The speed demon for building React apps. ???
- TypeScript: Your friendly code helper. ???
- AWS S3: The cosy home for your static files. ??
- AWS CloudFront: Your app’s global delivery superhero. ??
- AWS CLI: The magic wand for AWS commands. ??
Acknowledgement and Credits ??
An insightful article from? GeeksforGeeks inspired some parts of this guide. If you’re looking for even more details, check out their excellent article here.
And You’re Done! ??
Congratulations, your React app is now live and zipping across the globe faster than a viral reel on Instagram or a trending video on YouTube Shorts. ?? Whether you’re showing off your portfolio, building the next big thing, or just having fun, you’ve mastered the art of deployment!
So go ahead, share your app with the world, and watch the magic happen. ??
Pro Tip: Add a custom domain to your CloudFront distribution to make it extra cool! ??
This revised version ensures you give proper credit while keeping the article fun and engaging! ??
#ReactJS #WebDevelopment #AWS #TypeScript #Vite #FrontendDeveloper #DeployWebsite #CloudComputing #StaticWebsite #AmazonS3 #CloudFront #TechGuide #DevCommunity #CodingTips #WebDev
Software Engineer at Chimera Technologies Private Ltd. | Full Stack Developer | MERN Stack Developer | Frontend Developer | UI Developer | React Js | Redux Toolkit | Node.js | MongoDB | Express.js | Ci/Cd | Azure
2 个月Very helpful