Home > Net >  How do I redirect AWS S3 requests for missing files
How do I redirect AWS S3 requests for missing files

Time:08-19

I'm using S3 to store several hundred thousand images in a bucket, organized into several sub folders. Whenever a client application requests an image in any of these folders that is not found, I would like S3 to return a blanktile.png stored in the root of the same s3 bucket. I have configured the bucket's static web site properties with the following redirect rule but I still get 403's. All files in the bucket including the blanktile.png are marked as public.

[
    {
        "Condition": {
            "HttpErrorCodeReturnedEquals": "403"
        },
        "Redirect": {
            "ReplaceKeyWith": "blanktile.png"
        }
    }
]

Good image: https://dmtiles.s3.us-east-2.amazonaws.com/ALPWater/15/7696/21100.png

Missing image: https://dmtiles.s3.us-east-2.amazonaws.com/ALPWater/15/7696/random.png

Replacement file: https://dmtiles.s3.us-east-2.amazonaws.com/blanktile.png

CodePudding user response:

The ability to redirect to a 404 page is only available when using the Static Website URL. See: Configuring a custom error document - Amazon Simple Storage Service

The URL should look like:

http://bucket-name.s3-website.Region.amazonaws.com/object_key
  • Related