AWS - Host Static Files on S3
Updated at 2020-05-04 17:41
A simple step-by-step guide how to host some files on S3 with a CloudFront in the front.
AWS S3 + CloudFront + Route53 = https://static.example.com
Create bucket:
- Name: static.example.com
- Uncheck "Block all public access"
Create folder:
- Name: buttons
Upload images there:
- https://s3-eu-west-1.amazonaws.com/static.example.com/buttons/my-button.png
Create distribution:
- Origin Domain Name: static.example.com.s3.amazonaws.com
- Viewer Protocol Policy: Redirect HTTP to HTTPS
- Price Class: Use All Edge Locations
- Alternate Domain Names (CNAMEs): static.example.com
- Custom SSL Certificate: (select example.com certificate)
Record the distribution domain name: random-string-123.cloudfront.net
Wait for the distribution status to become "Deployed", takes about 20min.
Create record set:
- Name: static.example.com
- Type: A
- Alias: YES
- Value: random-string-123.cloudfront.net
Results:
- https://static.example.com/buttons/my-button.png which can be used by others
- You could host any files this way, of course you will be paying for the distribution costs, albeit minuscule.