Youtube tutorial: How to serve a static website hosted on AWS S3 bucket and AWS CloudFront with custom domain name
- make sure the
Block Public Access settings for this accountin AWS has all the checkboxes cleared/deselected - create a new
S3bucket - once you are within your bucket ->
Permissions->Block public access (bucket settings)clear all checkboxes - under
Permissions-> editBucket policyand use this policy to grant public read access for your website:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}- upload your files in the bucket
- once you are within your bucket ->
Properties->Static website hosting->Edit-> enableStatic website hosting - for
Index documentspecifyindex.html - for
Redirection rulesadd the following rules:
[
{
"Condition": {
"HttpErrorCodeReturnedEquals": "403"
},
"Redirect": {
"HostName": "aws.md.md",
"Protocol": "https",
"ReplaceKeyPrefixWith": "#!/"
}
},
{
"Condition": {
"HttpErrorCodeReturnedEquals": "404"
},
"Redirect": {
"HostName": "aws.md.md",
"Protocol": "https",
"ReplaceKeyPrefixWith": "#!/"
}
}
]instead of aws.md.md use your domain name
8. save changes
9. once you are within your bucket -> Properties -> Static website hosting -> copy the Bucket website endpoint without protocol (NO http:// !!!)
- go to
CloudFront->Create Distribution - use these properties:
Origin Domain Name: S3 bucket URL endpoint you've copied at point 9 (without protocolhttp://)
Viewer Protocol Policy:Redirect HTTP to HTTPS
Alternate Domain Names (CNAMEs): specify your custom domain name(s) (e.g:aws.md.md)
tickCustom SSL Certificate (example.com)and select from the autocomplete input box the certificate you've created inCertificate Manager
clickCreate Distributiondistribution button - Wait until your distribution has the
Status:Deployed
- go to
Route 53 - select your hosted zone
- click on
Create new record Record type:A - ...- toggle the
Aliasradio button, and specifyRoute traffic to: domain name of yourCloudFrontdistribution - click
Create records - wait until your zone is properly updated
- Open your domain -> you should see your website served from
S3bucket throughCloudFrontdistribution