Deploy a react static site to Amazon S3

A lifelong learner. Love to travel. Listen to music.
Search for a command to run...

A lifelong learner. Love to travel. Listen to music.
No comments yet. Be the first to comment.
Recently I cleared the AWS Certified Solution Architect Associate exam. While the memory is still fresh, I would like to share my journey. This is the notes I took during my preparation and the Github Repo. Who am I? I am a software engineer. My prim...
Best Practices for Path Structure, Versioning, and Error Handling

Understanding the Performance Implications of async and defer Attributes

Overview static: Default position. It does not allow setting properties like top, bottom, left, right, z-index relative: Acts the same as static. but allows positioning it relatively by putting properties like top, bottom, left, right, z-index absolu...

Overview When an element in the browser has a conflict of styles, the browser uses a set of rules to determine which style should be rendered. This set of rules is defined as CSS Selector Specificity. For instance, for an element, if we have the foll...

Master block, inline, flex, and grid to build better web layouts

Easier than you think.
Amazon S3 can be used to host a static website. Let’s walk through these simple processes.
The following properties are required to make an s3-bucket to host a static site
Enable Static Site Hosting
Need public access to the bucket along with the objects
A bucket policy to enable Get Object permission
Bucket name should be the same as a domain name
We will walk through the following steps to match with all the required configurations.
Go to AWS Console and open S3 service
Create a bucket and Uncheck Public Access
Bucket name should be the same as your website domain
If we consider the website should be www.my-site.com then, the bucket name should be my-site.com
If we plan to use the site domain [www.sub-domain.my-site.com](http://www.sub-domain.my-site.com) then the bucket name should be the same [www.sub-domain.my-site.com](http://www.sub-domain.my-site.com)
While creating a bucket, ensure you uncheck the Block all public access
Also, acknowledge the public access
To enable `static website hosting
Select the bucket and go to the properties tab
Now you will find an option to edit Static website hosting and click the Edit button
Enable the hosting
For a react app the index document should be index.html
We can create an error file and put it in the Error document section. Alternatively, we can use a dummy file name, even though it does not exist.
Now save the changes
To update bucket-policy select the bucket and go to the Permissions tab.
Select bucket-policy and click edit
Bucket policy be
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-name/*"
}
]
}
Here, Resource is the bucket arn
This policy implies that the bucket's object will be accessed publicly.
bucket-policyBefore uploading files to the bucket, build the react app and ensure build the directory is available in the react-app
build directoryNow the site is ready and you can find the URL in the following section
Select the bucket and go to the properties section
In properties, under the static site hosting you will find the URL for the site.
To use the domain from Route 53 .
Go to the hosted zone and create a new recordset with the following properties
Route name should be the same as the bucket name
Alias should be toggled in
As a value, from the dropdown select the s3 website endpoint
Also, select the region and bucket name from the value dropdown
Route type should be A record (IPv4)
Routing policy for the static site can be Simple Routing Policy
For further investigation, you can follow the Official doc by AWS.
Let me know of any queries, and I’ll reply ASAP.