Unable to point s3 bucket to Cloudfront Error Page

0

We have an SPA(Single page app) deployed in s3 bucket. Currently every route except the base route returns 404 from cloudfront. To solve this, we tried tweaking the error page configuration in Cloudfront distribution by setting the error page as "index.html" and returning 200 OK response status. But the "index.html" it gets pointed to is that of the ALB (the base bucket) and not to the desired s3 bucket. We want to point to "my-s3-bucket/index.html". Our application is designed in a way that each Cloudfront behavior points to a separate app in s3 bucket. Our Cloudfront behaviour is /logistics/* which points to my-s3-bucket

Is there a way we can point the index.html to the desired s3 bucket?

1개 답변
0

Try this: -Go to the CloudFront distribution.

  • Navigate to the ‘Origins’ tab and create a new origin pointing to my-s3-bucket. -Go to the ‘Behaviors’ tab and create a new behavior (or modify the existing one for /logistics/*) to point to the origin you created for my-s3-bucket.
  • Navigate to the ‘Error Pages’ tab.
    • Click on ‘Create Custom Error Response’.
    • For HTTP error code, choose 404.
    • For Customize Error Response, choose Yes.
    • For Response Page Path, input /index.html.
    • For HTTP Response Code, choose 200: OK.
    • Make sure this custom error response is associated with the /logistics/* behavior. By setting it up this way, when CloudFront encounters a 404 for a path under /logistics/*, it should serve the index.html from my-s3-bucket, and the SPA's router can then handle the route client-side. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html
AWS
Rumaisa
답변함 10달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠