Create a CloudFront distribution with Terraform (AWS)
Published in
3 min readJul 25, 2022
In this story, we will create a CloudFront distribution of a S3-hosted website.
Defining specifications
The alert will have the following features :
- Domain name: this is the endpoint of the S3 hosting the website;
- ID for the origin :
mywonderfulwebsite
; - Listening ports: 80 for HTTP, 443 for HTTPS;
- Origin protocol policy to be applied:
http-only
; - TLS protocols used by CloudFront in the case of HTTPS protocol: TLSv1, TLSv1.1, TLSv1.2
- End user requests at the root URL returns:
index.html
; - Protocol allowed to access the files in the origin :
redirect-to-https
; - compress the content of web requests that include
Accept-Encoding: gzip
in the header; - Processed HTTP methods by CloudFront:
GET
,HEAD
; - Caches the response to requests made with the HTTP methods:
GET
,HEAD
; - Don’t forward the request strings to the associated origin;
- Don’t forward cookies to the associated origin;
- Don’t restrict the distribution of content by country;
- Ensure that users use HTTPS for requests;
- HTTPS request handled by SNI only.