AWS - Setup S3 Website
Updated at 2017-04-13 23:39
This guide show how to host static website with HTTPS and CDN hosted on AWS S3.
AWS S3 => Create bucket named example.com
.
Properties => Permissions
Edit bucket policy:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "Allow Public Access to All Objects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example.com/*"
}
]
}
Properties => Static Website Hosting
[x] Enable website hosting
Index Document = index.html
Error Document = error.html
AWS S3 => Create bucket named www.example.com
.
Properies => Static Website Hosting
[x] Redirect all requests to another host name
Redirect all requests to = https://example.com
AWS CloudFront => Create Distribution => Web => Get Started
Don't use the Origin Domain Name
AWS suggests, copy-paste it from S3, the version with region as shown below.
Origin Settings
Origin Domain Name = example.com.s3-website-eu-west-1.amazonaws.com
Default Cache Behavior Settings
Viewer Protocol Policy = Redirect HTTP to HTTPS
Distribution Settings
Price Class = Use All Edge Locations
Alternate Domain Names = example.com
SSL Certificate
[x] Custom SSL Certificate
[Request or Import a Cerfiticate with ACM]
Create certificate for example.com and *.example.com
Confirmation will be sent to admin@example.com email
Default Root Object = index.html
AWS CloudFront => Create Distribution => Web => Get Started
Don't use the Origin Domain Name
AWS suggests, copy-paste it from S3, the version with region as shown below.
Origin Settings
Origin Domain Name = www.example.com.s3-website-eu-west-1.amazonaws.com
Distribution Settings
Price Class = Use All Edge Locations
Alternate Domain Names = www.example.com
SSL Certificate
[x] Custom SSL Certificate
Select the same certificate you requested earlier
AWS Route 53 => Hosted Zone => Create Record Set
Also create the hosted zone for example.com
if it doesn't exist.
example.com.
Type = A
Alias = Yes
Alias Target = example.com. (xxxxxxxx.cloudfront.net)
Routing Policy = Simple
Evaluate Target Health = No
AWS Route 53 => Hosted Zone => Create Record Set
www.example.com.
Type = A
Alias = Yes
Alias Target = www.example.com (yyyyyyyy.cloudfront.net)
Routing Policy = Simple
Evaluate Target Health = No