Skip to content

Commit 6b37a3a

Browse files
authored
Cache Next.js static assets on Cloudfront (#4278)
1 parent a1bfa50 commit 6b37a3a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

infrastructure/applications/cluster/cloudfront.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ data "aws_cloudfront_cache_policy" "caching_disabled" {
1212
name = "Managed-CachingDisabled"
1313
}
1414

15+
data "aws_cloudfront_cache_policy" "origin_cache_control_headers" {
16+
name = "UseOriginCacheControlHeaders"
17+
}
18+
1519
data "aws_acm_certificate" "cert" {
1620
domain = "pycon.it"
1721
statuses = ["ISSUED"]
@@ -60,6 +64,22 @@ resource "aws_cloudfront_distribution" "application" {
6064
compress = true
6165
}
6266

67+
ordered_cache_behavior {
68+
path_pattern = "/_next/static/*"
69+
allowed_methods = ["GET", "HEAD", "OPTIONS"]
70+
cached_methods = ["GET", "HEAD", "OPTIONS"]
71+
target_origin_id = "default"
72+
73+
cache_policy_id = data.aws_cloudfront_cache_policy.origin_cache_control_headers.id
74+
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.all_viewer.id
75+
76+
min_ttl = 0
77+
default_ttl = 86400
78+
max_ttl = 31536000
79+
compress = true
80+
viewer_protocol_policy = "redirect-to-https"
81+
}
82+
6383
restrictions {
6484
geo_restriction {
6585
restriction_type = "none"

0 commit comments

Comments
 (0)