Skip to content

Commit 67907c1

Browse files
committed
cache /go/* requests with query string
1 parent c57a58a commit 67907c1

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tf/cloudfront.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ resource "aws_cloudfront_distribution" "rko-router" {
7676
}
7777
}
7878

79+
ordered_cache_behavior {
80+
path_pattern = "/go/*"
81+
82+
allowed_methods = ["GET", "HEAD", "OPTIONS"]
83+
cached_methods = ["GET", "HEAD", "OPTIONS"]
84+
target_origin_id = "rko-router-lambda"
85+
viewer_protocol_policy = "allow-all"
86+
87+
cache_policy_id = aws_cloudfront_cache_policy.rko-router-querystring.id
88+
response_headers_policy_id = aws_cloudfront_response_headers_policy.rko-router.id
89+
90+
function_association {
91+
event_type = "viewer-request"
92+
function_arn = aws_cloudfront_function.rko-router-viewreq.arn
93+
}
94+
}
95+
7996
default_cache_behavior {
8097
allowed_methods = ["GET", "HEAD", "OPTIONS"]
8198
cached_methods = ["GET", "HEAD", "OPTIONS"]
@@ -124,6 +141,33 @@ resource "aws_cloudfront_cache_policy" "rko-router-default" {
124141
}
125142
}
126143

144+
resource "aws_cloudfront_cache_policy" "rko-router-querystring" {
145+
provider = aws.use1
146+
name = "rko-router-querystring"
147+
comment = "rko-router /go/* with query string in cache key"
148+
149+
min_ttl = 1
150+
default_ttl = 86400
151+
max_ttl = 31536000
152+
153+
parameters_in_cache_key_and_forwarded_to_origin {
154+
enable_accept_encoding_brotli = true
155+
enable_accept_encoding_gzip = true
156+
headers_config {
157+
header_behavior = "whitelist"
158+
headers {
159+
items = ["x-rko-host", "x-rko-xfp", "cloudfront-forwarded-proto", "cloudfront-viewer-country", "accept-language"]
160+
}
161+
}
162+
query_strings_config {
163+
query_string_behavior = "all"
164+
}
165+
cookies_config {
166+
cookie_behavior = "none"
167+
}
168+
}
169+
}
170+
127171
resource "aws_cloudfront_response_headers_policy" "rko-router" {
128172
name = "rko-router"
129173
comment = "rko-router"

0 commit comments

Comments
 (0)