Providing static html files output by StaticPress from Amazon S3, you can have a website with low cost and it will never go down. * This site using this system. This post tells you how to make this site. To host from S3, you need to:
- Create S3 Bucket to save your contents.
- Set the created S3 Bucket to use as your web site.
- Set it to accessible by your domain.
- Upload your contents to the S3 Bucket.
Create S3 Bucket to save your content.
First of all, login to you AWS Management Console and open Amazon S3 tab. https://console.aws.amazon.com/s3
Click the Create Bucket button.
Fill out the Bucket Name field. Bucket Name must be same as the site FQDN. So this site, the name is staticpress.net. Select the Region. For example, a site for users in Japan, it would be better to select Tokyo. After that, click Create. If you would like to save access logs, click Set Up Logging.
Enable your bucket for your web site
Right click the created S3 bucket, then select Properties from the menu. Click Static Website Hosting on the right side then select Enable website hosting. Input index.html for Index Document. Error Document specify the html file when 404 Not Found happens, so enter 404.html. Press the Save button to save the settings.
Next, add a bucket policy. For the default bucket policy, only you can browse, so add a policy to open to the Internet. You can use JSON format to set the policy details. Select permission and click Add bucket policy.
I put a sample bucket policy below. You can copy it and paste it in Bucket Policy Editor, and click the Save button.
* The bucket name of the sample is “example.com” so please replace it with the created bucket name in “”Resource”: “arn:aws:s3:::example.com/*”
Set the created bucket to use as your web sites.
Using sub domains, you don’t have to use Route 53, just set CNAME on your using DNS server. For example, using static.example.com, you may want to set like below:
static.example.com CNAME static.example.com.s3-website-ap-northeast-1.amazonaws.com
Using a root domain, you need to use Route 53. Login to AWS Management Console, then open the Route 53 tab.
Select Create Hosted Zone to create a new Hosted Zone. Then choose the created Hosted Zone and select “> Go to Record Sets”.
Select “A – IPv4 address” for Type and select “Yes” for “Alias”. Clicking Alias Target, you can find the S3 Bucket and ELB, so select the created S3 bucket. Then, at your domain registrar name server setting, set the name severs of the Hosted Zone NS records (usually 4 servers) as your domain’s name server.
Upload your content to S3 bucket
Now all you have to do is to upload all files of html, css, images and so on output by StaticPress to the S3 bucket. Here is the script for that below, so please give it a try:
* php 5.3 or later required.
* revise the line 10 to 14 as your environment.
* Also it needs AWS SDK for php 2, so download it from AWS.
Maybe this feature will be included in StaticPress.