Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3: Static Web Sites: Custom Domain or Subdomain

Amazon.com just announced that one can host static web sites in a S3 bucket. I went to their setup page at http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?WebsiteHosting.html and created a bucket for my static web site, and it worked fine. I have an URL of the form http://[my bucket name].s3-website-us-east-1.amazonaws.com/.

However, I would like to point a subdomain that I own (e.g. static.mydomain.com) to my static web site at Amazon S3. Has anybody figured out how to do that?

I appreciate any help you can give me.

like image 312
Jay Godse Avatar asked Feb 18 '11 16:02

Jay Godse


People also ask

Can Amazon S3 run a static website?

You can use Amazon S3 to host a static website. On a static website, individual webpages include static content. They might also contain client-side scripts. By contrast, a dynamic website relies on server-side processing, including server-side scripts, such as PHP, JSP, or ASP.NET.

Which S3 feature can be used to host static website?

To enable static website hosting Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to enable static website hosting for. Choose Properties. Under Static website hosting, choose Edit.


2 Answers

It turns out that to make it work, you cannot just map any arbitrary subdomain to any arbitrary bucket. The fully qualified subdomain name must be the same as the S3 bucket name.

  1. Suppose the name of your site is static.mydomain.com. Then you need to create a S3 bucket with that same name, named static.mydomain.com.
  2. Once you configure that bucket as a S3 static web site, it will have a URL assigned to it that looks something like http://static.mydomain.com.s3-website-us-east-1.amazonaws.com.
  3. Go to your domain host and map your subdomain to the URL from step 2. In enom.com, that meant mapping the host "static" to the address "static.mydomain.com.s3-website-us-east-1.amazonaws.com" as a CNAME record.

Thanks to Uriah and David for suggestions. I eventually got my answer at an Amazon AWS forum.

like image 143
Jay Godse Avatar answered Oct 05 '22 20:10

Jay Godse


Make sure that you follow the S3 DNS bucket naming conventions when creating your bucket.

Then:

  1. Enable S3 Website support for the bucket using the AWS Management Console at Properties --> Website

  2. Make sure the files in the bucket have public read permissions

  3. Try the website using the endpoint listed in the Management Console

  4. Setup your CNAME using the listed endpoint (e.g. www.example.com CNAME www.example.com.s3-website-us-east-1.amazonaws.com)

like image 44
Uriah Carpenter Avatar answered Oct 05 '22 22:10

Uriah Carpenter