AWS Builder Center

Deploying a React App on Amazon S3: 3 Mistakes That Broke My Site (and How I Fixed Them)

I deployed a React storefront on Amazon S3 with static website hosting, and three small mistakes broke it along the way: a typo that failed the build, a logo that went to the wrong folder, and a bucket policy rejected for an invalid resource. Here is the full process, what each error actually meant, and how I fixed it. A practical guide for students deploying their first static site.

I recently deployed a React storefront, built with Vite, on Amazon S3 using static website hosting. The steps are simple on paper. In practice, three small mistakes made it take much longer than expected. Here is the process, with the problems in the order I hit them.
The basic steps 1. Run npm run build to create the dist folder with the production files. 2. Create an S3 bucket and turn off Block all public access, since a website has to be public. 3. Upload the contents of dist. 4. Enable static website hosting in the bucket properties and set index.html as the index document. 5. Add a bucket policy that allows public read access to the objects. 6. Open the bucket website endpoint.
Mistake 1: a typo that broke the build npm run build failed and pointed to one file and one line. An extra letter had slipped into the code. Reading the error log carefully took me straight to it. Lesson: build errors usually tell you exactly where the problem is.
Mistake 2: the missing logo The site loaded, but the logo was a broken image. The code requested the logo from an images folder, but my upload had put the file at the top level of the bucket. The file's own link in the console opened the image fine, which made me think everything was OK. Opening the logo through the website endpoint with the exact path (/images/logo.png) showed the real problem. The fix was to delete the stray file and upload the images folder so the structure matched what the code expected. Lesson: your bucket must mirror the dist folder structure exactly.
Mistake 3: the bucket policy error My public read policy was rejected with an invalid resource error. The bucket name in the policy has to match the real bucket name exactly, and the resource must end with /*. Copying the bucket ARN from the policy editor fixed it.
Two things worth knowing - The S3 website endpoint uses http, not https. For a portfolio project that is fine, and CloudFront is the usual next step for https. - A public bucket should contain website files only. No zip archives, no environment files.
What is next I plan to add CloudFront and then deploy the backend. The project is small, but debugging three real problems taught me more about S3 than reading the documentation did.
Which mistake have you made when deploying a static site?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article