Use Amazon S3 to serve your Website

An Amazon S3 bucket is very suitable to serve your static content in an serverless way. You don´t have to waste even a single thought on scaling. It makes no difference if you must serve one file per second or thousands and you pay only for the traffic your site is generating.

This post provides an overview of how to use S3 as an Webserver for static Content. It starts with the most simple way and goes down to more advanced options.

Enable Website Hosting for a Bucket

This is the most trivial option to use an S3 bucket to serve the static content of a website is to enable this feature on the „Properties“ Tab for that S3 bucket or to use the CLI.

S3_Website_Hosting

aws s3 website s3://my-bucket/ –index-document index.html

This solution has several drawbacks and is also not the AWS preferred way.

  • The URL ist not very readable
  • Only HTTP is supported
  • The S3 bucket and every object that should be served must be public

Using Route 53 and enabled Website Hosting

Option Two is a combination of enabled Website Hosting and the use of Amazon Route 53.

Route 53 is Amazons DNS Service. If your Site domain is managed by Route 53 it is possible to configure a S3 bucket as an DNS alias e.g to serve your content under example.com. The picture shows that configuration for my private domain. The only prerequisite is that the S3 bucketname is equal to your DNS Record Name. For the domain marcobuss.de the bucketname must be also marcobuss.de. Because bucketnames are globally it is possible that your needed name is already used by an other user.

Route_53_S3_alias

With this option we get a more convenience url, but your content is also available under the S3 default URL, HTTPS is not supported and all Content must be public readable.

Use CloudFront and Route 53 to deliver Content from S3

At the End the most advanced options that gives plenty of options and is the AWS preferred way for deliver static content from an S3 bucket. We use CloudFront and Route 53 in combination. The following picture shows that solution.

With such a setup it is possible to map every bucketname to your domain name, the bucket can be private and we can restrict the access to allow only https.

For a more detailed Description and an example read the following blogpost.

Overview_Diagram

 

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.