Skip to content

Instantly share code, notes, and snippets.

@Kiougar
Last active May 14, 2019 13:15
Show Gist options
  • Select an option

  • Save Kiougar/45457d0cb6b1ecbba6e1b4f52a74da36 to your computer and use it in GitHub Desktop.

Select an option

Save Kiougar/45457d0cb6b1ecbba6e1b4f52a74da36 to your computer and use it in GitHub Desktop.
How to create and configure a static website on AWS

Create a static website on AWS

https://console.aws.amazon.com/quickstart-website

Add a name and select example website. To get the S3 bucket name that was created: Click Manage files in Amazon S3.

Domain Settings

  1. Click Buy domain
  2. Click Choose existing domain
  3. Select the domain and enter an optional subdomain

Allow some time for the newly created Record Set to propagate.

CloudFront Settings

Click Manage settings in Amazon CloudFront

General tab

  1. Click Edit
  2. Add the alternate domain names, e.g.:
    www.example.com
    example.com
    
  3. Select the appropriate certificate
  4. Select the desired Security Policy
  5. Select the supported HTTP Versions
  6. Save by clicking Yes, Edit

Behaviors tab

  1. Edit the first behavior item
  2. Select Redirect HTTP to HTTPS in the Viewer Protocol Policy
  3. Set Object Caching variables (or select Use Origin Cache Headers)
  4. Set Yes to Compress Objects Automatically
  5. Save by clicking Yes, Edit

Error Pages tab

If your website is not an SPA, you can ignore this part

  1. Click Create Custom Error Response
  2. Select HTTP Error Code 404: Not Found
  3. Set Yes on Customize Error Response
  4. Type /index.html in Response Page Path
  5. Set HTTP Response Code to 200: OK

Do the same for all the other error codes you want to handle.

Redirect naked domain to www

The following steps assume the scenario where we want http://example.com or https://example.com to be redirected to https://www.example.com

Create a new S3 Bucket

  1. Type a Bucket Name e.g.: aws-example-redirect
  2. Select US East (N. Virginia) as the region
  3. Click Create bucket
  4. Open the newly created bucket
  5. Go to the Properties tab
  6. Click Static website hosting
  7. Select Redirect requests
  8. Type www.example.com as the domain and https as the protocol
  9. Copy the endpoint URL
  10. Click Save

Create a new CloudFront distribution

  1. Paste the bucket's endpoint URL (that was copied from the previous step) as the Origin Domain Name
  2. Select the appropriate Price Class
  3. Type example.com in the Alternate Domain Names
  4. Select the appropriate SSL Certificate
  5. Create Distribution

Create a new Record Set

  1. Leave Name empty
  2. Set Yes to Alias
  3. Select the CloudFront distribution from the previous step as the Alias Target
  4. Create record set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment