cloudfront, s3, frontend, react, spa,

Static serving SPA with CloudFront

Ngoc Ngoc Follow Dec 02, 2023 · 1 min read
Share this

Connecting domain to cloudfront with route53

  • It is possible that your cloudfront is not shown on the list when you trying to connect your domain using AWS Route53.

route53ruleA

  • First, check your cloudfront setting.

cloudfront setting

  • Make sure domain properly entered on CNAME
  • It should match with the record name on route53. (first image)

Access denied when access via specific url

  • You might get access denied error when you trying to access with specific url.

cloudfront access denied

  • This is because SPA need “index.html” for every request.
  • You need to set custom error response on your cloudfront distribution.

cloudfront custom error

  • You also need so change your s3 bucket policy. s3Policy
  • First statement is to give cloudfront “get” access to s3.
  • Second statement is to catch 404 response instead of 403 or 400 from cloudfront.
  • It is better to catch 404 since 403 is returned by WAF.

Now, you can access any url besides the base url.

XML file does not appear error

  • If you don’t set default root object on your CloudFront settings, you might face this error. root domain error

  • It can be solved by setting index.html as your default root object. cloudfront setting

  • References

Ngoc
Written by Ngoc Follow
Hi, I am ngoc, the Blog Editor of "Trending source", the the site you're currently previewing. I hope you like it!