Create an s3 bucket
First, you'll need to create a bucket for your website and set it up to host a static website.
Note
A static website is one that doesn't require any server-side processing. If you
requiree
a full-blown blog engine like WordPress or use some other software to serve your website (This
site previously ran on DokuWiki), you won't be able to serve it using S3.
I recommend using a bucket that's named after your website (if you use Route53 to route traffic,
you'll need to do this anyway). Here's how:
aws s3 mb s3://www.my-domain-name.com
That's an example value. Use your own domain name in place of my-domain-name, or choose some
suitably unique name.
Give your website some content
Next, provide some content for your bucket. To begin, you might just want to create a simple page
and upload it to the bucket. Here's a good test page:
<html>
<body>
<h1>Hello, My Awesomely Static Website!</h2>
</body>
</html>
Just type (or cut/paste) it into a file called index.html
and then send it to your bucket
like this:
aws s3 cp --acl public-read index.html s3://www.my-domain-name.com
The --acl public-read
option makes sure that all the files in my website can be accessed by
anyone. By default, S3 copies files privately, so only you have permission to view the files
you've copied. While it's sort of cool to have a website that only you can view, it's also a bit
lonely.
Set up your bucket as a website
Now you can set up your bucket as a website by giving it a website configuration:
aws s3 website s3://www.my-domain-name.com --index-document index.html
That's all it takes. Amazon S3 gives your website a URL such as
http://www.my-domain-name.com.s3-website-us-west-2.amazonaws.com
, where the bit before
s3-website
is your bucket name, and us-west-2
is the region that you created the bucket in.
Note
By default, the AWS CLI uses us-west-2 as the default region. If you didn't set a
region when setting up your AWS CLI configuration, that's where you'll find it.
I highly recommend using a region that's close to you geographically! You can find a list of
AWS regions and endpoints for S3 on the AWS Regions and Endpoints page.
If you've followed all the steps so far, type the URL of your website in your web browser's address
bar, and take a look at your site!