0

Home page (index.html) working fine with cloudfront mapped url but when i go to any other page and refresh i get an error.

I tried with Bucket policy ::

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowCloudFrontServicePrincipalReadOnly",
            "Effect": "Allow",
            "Principal": {
                "Service": "cloudfront.amazonaws.com"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucket/*",
            "Condition": {
                "StringEquals": {
                    "AWS:SourceArn": "arn:aws:cloudfront::XXXXXXXXX:distribution/XXXXXXX"
                }
            }
        }
    ]
}

But I get an error below when i access with cloudfront url. Note that i've disabled S3 public access so it cannot be accessed directly.

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>6NYF5R63KS7PFW89</RequestId>
    <HostId>
        bfVPlbFcw8tSr0CnMIEyRiLeTw3CrAOc7d6v8xw1YGl0YoIr1yWO7tgTQDsqKI5NdU0D0t9a/EU=
    </HostId>
</Error>
Bas H
  • 2,114
  • 10
  • 14
  • 23
  • Is this Single Page Application ? Have you tried setting CustomErrorRepsonse in Cloudfront to redirect to your index.html page ? https://stackoverflow.com/questions/16267339/s3-static-website-hosting-route-all-paths-to-index-html – NSS Mar 27 '23 at 12:54
  • Yes, i added the CustomErrorResponse and it works fine now. But in network tab i still see x-cache: Error from cloudfront – Usman Mahmood Mar 28 '23 at 05:07
  • Can you share more details on the error, screenshots and when you are getting the error etc.? – NSS Mar 28 '23 at 10:38

0 Answers0