S3 replacing default xml error with custom error not working

Viewed 159

I feel stupid for having to ask this but I cannot get amazon's s3 error document to work. What I want to do is show a custom error document when a user tries to access a file that doesn't not exist. So I followed to documentation at https://docs.aws.amazon.com/AmazonS3/latest/userguide/CustomErrorDocSupport.html but this simply doesn't work.

I can access files that exist but when I enter https://mybucketurl/notexistingdoc.html it trows the usual access denied/key not found xml error.

As the documentation is pretty barebones and it there isn't much to configure I have no clue what is wrong. I even tried setting to permissions on my bucket to s3:* to make sure it wasn't a permission issue.

1 Answers

This is what is tried and my error page also works.

  • Created a bucket, changed permission to make it public.

  • under permission -> block public access turn it off , and
    attached a policy bucket policy to grant public read access to your bucket. When you grant public read access, anyone on the internet can access your bucket.

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "PublicReadGetObject",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:GetObject",
                "Resource": "arn:aws:s3:::your-bucket name/*"
            }
        ] }
    
  • upload your index.html and error.html as objects

  • my error.html file <h1>there was an error</h1>

  • Go to properties, under static website hosting,enable it,choose a hosting type as static, mention exact names index.html for index document and error.html for error document nd then you can verify it by trying to access your bucket URL with anything which doesn't exist it will render the error page

For detailed explanation follow docs

Related