Contents

How to Quickly Host a Static Website on AWS S3 with SSL

aws website hosting host a website on aws ec2 website on aws aws website

aws ec2 website hosting host website on aws ec2 how to host website on aws amazon aws website hosting how to host a website in aws aws s3 static website aws host static website host static website on aws host website on aws aws ec2 host website aws website builder hosting website on aws host a website on aws hosting a website on aws how to host a dynamic website on aws how to host a website on aws ec2

https://docs.aws.amazon.com/AmazonS3/latest/userguide/website-hosting-custom-domain-walkthrough.html

Static Site on S3 with SSL and non-www to www Forwarding

  • 2 S3 buckets. www or non-www bucket set to forward to the one you want. Make sure to set a access policy.

  • 2 Cloudfront Distributions. One for each S3 bucket.

  • For Cloudfront distribution for desired www/non-www, make add the Cloudfront distribution to the pretty url function.

  • Route 53 A and AAAA records Alias to Cloudfront distributions for www and non-www respectively.

  • Request SSL certificate through Certificate Manager. Make sure naked url and www url subdomain are included. Verify via Route 53 cname entry.

  • Need to use script for clean URLs - Add in CloudFront functions > lens-guide-pretty-urls > publish.

  • Upload files

  • CloudFront > Distributions > Select correct distribution > Invalidations, enter " /* " to invalidate all files.

Hosted Zone

Go into Route 53 Create new hosted zone. (will see other URLs listed) Enter URL Copy & Paste into the script.

Create S3 Buckets

domain.com
www.domain.com - this will be forwarded to root (Actually don't think this domain is needed)

Allow public access to all files. This saves doing the step later.

Enable Static Site Hosting

how to host a website on aws Go into root domain settings on S3 Go to the Properties tab Scroll to bottom and edit the ‘static website hosting’ options set to enable index.html 404.html

Go to other bucket properties for either www or non-www version. Enable static site hosting. Forward to other site, ie www.site-example.com to site-example.com

Setup Logging?

aws website hosting cost can log visits?

Allow Public Access

Go to the permissions tabs

Edit the Block public access (bucket settings) Allow public access

This can be done when the bucket is created.

Upload Files to S3 Bucket

Upload at least an index.html file to allow the site to be accessed.

Set a Bucket Policy

add a bucket policy make sure to change the Bucket-Name below The correct bucket name can be found under the ‘Properties’ tab for the bucket.

{ “Version”: “2012-10-17”, “Statement”: [ { “Sid”: “PublicReadGetObject”, “Effect”: “Allow”, “Principal”: “”, “Action”: [ “s3:GetObject” ], “Resource”: [ “arn:aws:s3:::Bucket-Name/” ] } ] }

Fordward Subdomain to Domain

CloudFront Go into Distributions Go into the settings for the distribution associated with the desired domain The “Alternate domain name (CNAME) - optional” needs to include the www and naked version of the domain www.domain.com domain.com A custom SSL certificate can be requested. It is nessecary to have the verification added to the Route 53 entry. The CloudFront options will not be able to be saved unless this is done correctly.

’’’ # I THINK THIS IS WRONG Forward the www subdomain to domain goto www.domain.com bucket settings Under the permissions tab edit the static website hosting option enable static website hosting ‘Hosting type’ select redirect requests for an object ‘Host name’ domain.com ‘Protocol’ https (choosing http will fuck shit up? I had it set at first and I got weird redirect behavior) ’’’

Goto domain.com settings Properties tab ‘Static website hosting’ is at the bottom of the page ‘Bucket website endpoint’ Click the link, which should open in a new tab. if it works, save the link

should be a URL with the following format:

domain.com.s3-website-us-east-1.amazonaws.com/

pretty URLs?

Add alias records?

Route 53

Do not need to register a domain through Amazon.

Create a ‘hosted zone’ for domain. Update the DNS entries on registar (NameCheap) with S3 DNS server addresses

CloudFront for SSL (S3 REST API)

https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/

Go to CloudFront (Need to use S3 REST API endpoint in order to use HTTPS) Click create distribution ‘Origin domain’ fill in with ‘Bucket website endpoint’ recorded earlier or select from the dropdown menu ‘S3 bucket access’ Select Yes use OAI Select ‘Yes, update the bucket policy’ push the ‘Create new OAI’ button

‘Viewer protocol policy’ Redirect HTTP to HTTPS

Function associations - will have to add lamda edge here

‘Alternate domain name (CNAME)’ Push the ‘Add item button’ enter domain.com

‘Custom SSL certificate’ Push the ‘Request certificate link’

Only HTTPS://lens-guide.org working. HTTP://lens-guide.org forwards to HTTPS HTTPS://www.lens-guide.org, HTTP://www.lens-guide.org

Request SSL certificate

Verification can take up to 30 minutes after the record has been added to Route 53.

https://docs.aws.amazon.com/acm/latest/userguide/dns-validation.html

Leave as request a public certificate and push next ‘Fully qualified domain name" domain.com and www.domain.com Leave all other options as default Press Request Click on the certificate number to go to the option screen Under ‘Domains’ click the ‘Create records in Route 53’ button if no record shows up, go back, wait a minute, and then try again Make sure the box is checked and press the ‘Create records’ button Close the page

Push the refresh button Select the newly created certificate

‘Defaut root object’ index.html (this is so pretty urls will work correctly for the root domain with /)

‘Description’ domain.com

Push the ‘Create distribution’ button

Settings page will show ‘Standard logging’ as being off

Go to the CloudFront Distributions page - May need to wait for the instance to deploy. copy the ‘Domain name’ address

d1hfmbf0sdbpw7.cloudfront.net

Create the following records to the CloudFront distribution URL. All the same. Use option - Alias to CloudFront Distribution A - example-site.com AAAA - example-site.com A - www.examplesite.com AAAA - www.examplesite.com

Add name servers to domain registar

Add the Amazon name servers to the Custom DNS on NameCheap for the domain name.

This can take 24-48 hours to propigate.

Create A and AAAA DNS Records

aws static website

Go to Route 53 Go to the domain.com options ‘Create records’ Add A and AAAA records to www.domain.com and domain.com pointing to the Cloudfront address www goes in the ‘Record name’ box ‘Route traffic’ to Alias select ‘Alias to CloudFront distribution’ select the recorded cloudfront address from ealier had to do in 2 separate enteries, once without www and then once with. Otherwise I got an error message.

How long for the DNS to updage? I did final changes at 2:30 PM 3 PM site shows up. HTTPS forwarding doesn’t seem to currently be working correctly. www not forwarding to non-www

S3 CloudFront, Cloudfront logging? CloudFormation IAM Lambda Route53 Certificate Manager

Pretty URLS

I think this is what actually worked. Need to create a cloudformation in order to trigger the CloudFunction. Brutally difficult to find out what to do. https://robkenis.com/posts/hugo_pretty_urls_on_aws/

Didn’t work

https://github.com/CloudUnder/lambda-edge-nice-urls

S3 Object Versioning

This will clear the CloudFront cache and allow updates to show up. If this isn’t done it will be 24 hours before the cache is updated.

https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serving-outdated-content-s3/