AWS Builder Center

One CloudFront domain for a React app and its API

For our hackathon project, Deadman, I built the web interface in React with Vite, hosted on S3 and served through CloudFront. The API sits behind API Gateway.

student
A choice that saved us time: CloudFront serves the website from S3 and forwards /api/* to API Gateway on the same domain. That means the browser makes same-origin requests, so we needed no CORS setup at all. The catch is that the /api behaviour has to allow POST, since CloudFront only allows GET and HEAD by default, and it must forward the Authorization header.
Two interface details mattered. The countdown is computed from the server's expires_at minus its server_time, not from the browser's clock, so a wrong laptop clock cannot lie about how long is left. And every API error code maps to a plain-language message, because the person using it is likely under stress.
After the first live tests, I also hardened the failure path so a failed timer setup ends in a clear FAILED state and releases the lock, with tests that read the record back instead of trusting the response.
Finally: after uploading a new build to S3, the old site kept showing until we invalidated the CloudFront cache. Build the invalidation into your deploy script.
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