@@ -5,19 +5,21 @@ Below is an examples of calling this module.
55```
66module "cloudfront" {
77 source = "./cloudfront"
8- origin = {
9- domain_name = "s3_bucket_regional_domain_name"
10- origin_id = "s3_bucket_name"
11-
12- ## We can only use Any one of Origin Access Control or Origin Access Identity
13- # For Origin Access Control
14- origin_access_control_id = "s3_cloudfront_origin_access_control_id"
15- # For Origin Access Identity
16- s3_origin_config = {
17- s3_origin_access_identity = "s3_cloudfront_origin_access_identity_path"
18- }
8+ origin = [
9+ {
10+ domain_name = "s3_bucket_regional_domain_name"
11+ origin_id = "s3_bucket_name"
1912
20- }
13+ ## We can only use Any one of Origin Access Control or Origin Access Identity
14+ # For Origin Access Control
15+ origin_access_control_id = "s3_cloudfront_origin_access_control_id"
16+ # For Origin Access Identity
17+ s3_origin_config = {
18+ s3_origin_access_identity = "s3_cloudfront_origin_access_identity_path"
19+ }
20+
21+ }
22+ ]
2123 domain_aliases = ["example.com", "www.example.com"]
2224 acm_arn = "acm_arn"
2325}
@@ -27,62 +29,67 @@ module "cloudfront" {
2729```
2830module "cloudfront" {
2931 source = "./cloudfront"
30- origin = {
31- domain_name = "s3_bucket_regional_domain_name"
32- origin_id = "s3_bucket_name"
32+ origin = [
33+ {
34+ domain_name = "s3_bucket_regional_domain_name"
35+ origin_id = "s3_bucket_name"
3336
34- ## for http endpoint
35- custom_origin_config = {
36- origin_protocol_policy = "http-only"
37- }
38- ## for https endpoint
39- # custom_origin_config = {
40- # origin_protocol_policy = "https-only"
41- # }
42-
43- ## We can restrict publically accessible endpoint by adding custom headers in request sends from cloudfront to custom origin endpoint and validate headers on origin endpoint side
44- custom_header = [
45- {
46- name = "Referer"
47- value = "https://example.com"
48- },
49- {
50- name = "Referer"
51- value = "https://www.example.com"
52- }
53- ]
54-
55- domain_aliases = ["example.com", "www.example.com"]
56- acm_arn = "acm_arn"
57- ## it's helpful to handle 404 to redirect on index.html with 200 response for read based build
58- custom_error_response = [
59- {
60- error_caching_min_ttl = 300
61- error_code = 404
62- response_code = 200
63- response_page_path = "/index.html"
37+ ## for http endpoint
38+ custom_origin_config = {
39+ origin_protocol_policy = "http-only"
6440 }
65- ]
41+ ## for https endpoint
42+ # custom_origin_config = {
43+ # origin_protocol_policy = "https-only"
44+ # }
45+
46+ ## We can restrict publically accessible endpoint by adding custom headers in request sends from cloudfront to custom origin endpoint and validate headers on origin endpoint side
47+ custom_header = [
48+ {
49+ name = "Referer"
50+ value = "https://example.com"
51+ },
52+ {
53+ name = "Referer"
54+ value = "https://www.example.com"
55+ }
56+ ]
57+ }
58+ ]
59+
60+ domain_aliases = ["example.com", "www.example.com"]
61+ acm_arn = "acm_arn"
62+ ## it's helpful to handle 404 to redirect on index.html with 200 response for read based build
63+ custom_error_response = [
64+ {
65+ error_caching_min_ttl = 300
66+ error_code = 404
67+ response_code = 200
68+ response_page_path = "/index.html"
69+ }
70+ ]
6671}
6772```
6873
6974## Cloudfront distribution with s3 Origin with TTL value
7075```
7176module "cloudfront" {
7277 source = "./cloudfront"
73- origin = {
74- domain_name = "s3_bucket_regional_domain_name"
75- origin_id = "s3_bucket_name"
76-
77- ## We can only use Any one of Origin Access Control or Origin Access Identity
78- # For Origin Access Control
79- origin_access_control_id = "s3_cloudfront_origin_access_control_id"
80- # For Origin Access Identity
81- s3_origin_config = {
82- s3_origin_access_identity = "s3_cloudfront_origin_access_identity_path"
83- }
78+ origin = [
79+ {
80+ domain_name = "s3_bucket_regional_domain_name"
81+ origin_id = "s3_bucket_name"
8482
85- }
83+ ## We can only use Any one of Origin Access Control or Origin Access Identity
84+ # For Origin Access Control
85+ origin_access_control_id = "s3_cloudfront_origin_access_control_id"
86+ # For Origin Access Identity
87+ s3_origin_config = {
88+ s3_origin_access_identity = "s3_cloudfront_origin_access_identity_path"
89+ }
90+
91+ }
92+ ]
8693 domain_aliases = ["example.com", "www.example.com"]
8794 acm_arn = "acm_arn"
8895
@@ -94,4 +101,79 @@ module "cloudfront" {
94101 default_ttl = 3500 # default amount of time that you want objects to stay in cloudfront cache before it sends another request to origin
95102 }
96103}
104+ ```
105+
106+ ## Cloudfront distribution with multiple origin and cache behavior
107+ ```
108+ module "cloudfront" {
109+ source = "./cloudfront"
110+ origin = [
111+ {
112+ domain_name = "domain_name"
113+ origin_id = "origin_id"
114+ },
115+ {
116+ domain_name = "domain_name"
117+ origin_id = "origin_id"
118+ origin_path = "/origin_path"
119+ }
120+ ]
121+
122+ domain_aliases = ["example.com", "www.example.com"]
123+ acm_arn = "acm_arn"
124+
125+ default_cache_behaviour_target_origin_id = default_cache_behaviour_target_origin_id
126+ allowed_methods = ["list of allowed methods"]
127+ cache_policy_id = aws_managed_cache_policy_id
128+
129+ ## Can be used only if cache_policy_id is not used
130+ # forwarded_values = {
131+ # query_string = true
132+ # query_string_cache_keys = ["list of query string cache keys"] # set only if query_string is true and not all query string are meant to be cached
133+ # headers = ["list of headers"] # specify * to include all headers
134+ # cookie_forward = ""
135+ # cookies_whitelisted_names = ["list of whitelisted cookie names"] # specify only if cookie forward is set to whitelist
136+ # }
137+
138+ ## Can be used only if cache_policy_id is not used
139+ # ttl_values = {
140+ # min_ttl = 0
141+ # max_ttl = 31536000
142+ # default_ttl = 86400
143+ # }
144+
145+ ordered_cache_behavior = [
146+ {
147+ path_pattern = "path_pattern"
148+ target_origin_id = origin_id
149+
150+ ttl_values = {
151+ min_ttl = 0
152+ max_ttl = 31536000
153+ default_ttl = 86400
154+ }
155+
156+ forwarded_values = {
157+ query_string = true
158+ }
159+
160+ ## Used to associate a cloudfront_function
161+ function_association = [
162+ {
163+ event_type = "event_type"
164+ function_arn = cloudfront_function_arn
165+ }
166+ ]
167+
168+ ## Used to associate a lambda_function
169+ lambda_function_association = [
170+ {
171+ event_type = "event_type"
172+ lambda_arn = lambda_function_arn
173+ include_body = true
174+ }
175+ ]
176+ }
177+ ]
178+ }
97179```
0 commit comments