Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AmazonS3: custom error pages

I am planning to share URLs (time limited) for private objects. Is there a way to set custom error pages for 404/403 http responses ?

like image 335
Amit Avatar asked Mar 31 '11 12:03

Amit


1 Answers

Yes, it's possible, see this announcement. In the Developer guide there is a paragraph about "Custom Error Document Support" where I read the following sentence.

You can optionally provide a custom error document with a user-friendly error message and with additional help. You provide this custom error document as part of adding website configuration to your bucket. Amazon S3 returns your custom error document for only the HTTP 4XX class of error codes.

How to set 4xx custom error page:

  • With CloudBerry, you can right click on a bucket, select Properties, click the tab Website and set the index document and the 4xx error document.

  • Use AWS Java SDK, here is an example code (not tested)

    AmazonS3 client = new AmazonS3Client(new BasicAWSCredentials(
        "accessKey", "secretKey");
    BucketWebsiteConfiguration conf = new BucketWebsiteConfiguration(
        "index.html", "404.html");
    client.setBucketWebsiteConfiguration("bucketname.example.com", conf);
    

UPDATE I also found this blog post: Host Your Static Website on Amazon S3.

like image 196
stivlo Avatar answered Oct 07 '22 00:10

stivlo