Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2016 18:36
Show Gist options
  • Save JamesChevalier/07ed363093c0bdd1e07d53ecd0afb91f to your computer and use it in GitHub Desktop.
Save JamesChevalier/07ed363093c0bdd1e07d53ecd0afb91f to your computer and use it in GitHub Desktop.
How to set up S3/CloudFront/SSL

Create an SSL Certificate for your website

  • In the Certificate Manager console, click the Request a certificate button
  • Enter the domain name in the field
  • Click the Review and request button
  • Click the button in the email that this request sends you to validate the request

Create the bucket for your website in S3

  • Create a new bucket in s3
  • In the Permissions section, click the Edit bucket policy button and paste this in (swapping out BUCKET_NAME with the name of your bucket):
	"Version": "2012-10-17",
	"Statement": [
			"Sid": "PublicReadGetObject",
			"Effect": "Allow",
			"Principal": {
				"AWS": "*"
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::BUCKET_NAME/*"
  • Enable it for Static Website Hosting
    • Set Index Document to index.html
    • Set Error Document to index.html
  • Copy the Endpoint listed (something like

Connect your website in S3 to a new CloudFront Distribution

  • Create a new Web CloudFront Distribution
  • Paste in the Endpoint you previously copied into the Origin Domain Name field
  • Set Origin Protocol Policy to HTTP Only
  • Set Viewer Protocol Policy to Redirect HTTP to HTTPS
  • Set Price Class to Use Only US and Europe (or not, who knows)
  • Set Alternate Domain Names to the domain that you're creating, e.g.
  • Set SSL Certificate to Custom SSL Certificate (
    • Select the appropriate SSL Certificate from the pull down menu in this section
  • Set Default Root Object to index.html
  • Click the Create Distribution button
  • In the CloudFront Distributions list page, click on the new distribution's ID
  • Click on the Error Pages tab
  • Click the Create Custom Error Response button
  • Set HTTP Error Code to 404: Not Found
  • Set Error Caching Minimum TTL to 0
  • Set Customize Error Response to Yes
  • Set Response Page Path to /index.html
  • Set HTTP Response Code to 200: OK
  • Save

Configure DNS to serve the new CloudFront Distribution

  • Add a new CNAME entry for your domain name
    • Set Host to www (or whatever subdomain you're setting up)
    • Set the location to the Domain Name that's listed in the CloudFront Distributions list page e.g.
    • Save the changes and wait for DNS changes to propagate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment