Advertisement
andrejsstepanovs

by hand static S3 website setup

Mar 24th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. # 0) buy domain (namecheap.com)
  2. # 1) AWS S3
  3. In AWS create bucket with same name as domain (! with "www." as prefix !). Save. Then edit it
  4. - Permissions: uncheck all except "ACLs" related.
  5. - Bucket policy:
  6. {
  7. "Version": "2012-10-17",
  8. "Statement": [
  9. {
  10. "Sid": "PublicRead",
  11. "Effect": "Allow",
  12. "Principal": "*",
  13. "Action": "s3:GetObject",
  14. "Resource": "arn:aws:s3:::BUCKETNAMEHERE/*"
  15. }
  16. ]
  17. }
  18. - Properties: Static website hosting: Enabled
  19. - Copy "Bucket website endpoint" url
  20.  
  21. # 2) namecheap.com
  22. - edit domain
  23. - Advanced DNS:
  24. | Type | Host | Value | TTL |
  25. | CNAME Record | www | FULL-BUCKET-WEBSITE-ENDPOINT-URL-HERE | 30 min |
  26. | URL Redirect Record | @ | http://www.YOURDOMAINHERE/ | Unmasked | |
  27.  
  28. # 3) hugo
  29. - installation
  30. - goto https://github.com/gohugoio/hugo/releases > download Linux-64bit.deb > install
  31. - hugo new site APPNAMEHERE
  32. - cd APPNAMEHERE > git init
  33. - find hugo template you like and follow install instructions as submodule
  34. - hugo server
  35. - edit until you are happy. make sure urls end with "*.html" because it cloudfront will not be able to auto find it without lambda and thats costly
  36. - hugo -D
  37.  
  38. # 4) upload to bucket
  39. - aws --profile private s3 cp /var/www/USER/APPNAMEHERE/public/ s3://BUCKETNAMEHERE/ --recursive
  40.  
  41. # 5) HTTPS
  42.  
  43. AWS Certificate Manager
  44. - Switch to zone "US East (N. Virginia)us-east-1"
  45. - if new -> Provision certificates
  46. - follow procedure. Choose DNS check (dont use email check)
  47. - you will be given CNAME record to add
  48. - go to namecheap domain -> Advanced DNS
  49. - "ADD NEW RECORD" -> CNAME Record -> first value from given (but drop the domain name. keep www at the end) -> value paste as is full -> TTL 5min (after certificate will be issued can change to longer)
  50. - on aws side continue. should be Status -> issued
  51.  
  52. CloudFront
  53. - Create Distribution -> Get Started
  54. - Origin Domain Name - choose your bucket
  55. - Alternate Domain Names: enter your "www.domain.com"
  56. - Default Root Object: index.html
  57. - SSL Certificate:
  58. - Select Custom SSL Certificate -> select your certificate from dropdown. (if option is greyed out then certificate is not in correct zone. needs to be us-east-1)
  59. - Set up other options based on your taste.
  60. - Save it.
  61. - Get xxxxxxx.cloudfront.net url and paste it in namecheap "CNAME Record" Host=www value. So now it is not pointing to bucket but to cloudfront.
  62.  
  63. - copy Origin address from S3 Static website. Auto pick is not correct one. There /index.html will not be found. Example correct one: `www.accshiftassist.com.s3-website.eu-central-1.amazonaws.com`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement