From 27523bc2b09ad1b84a06f0cdc138513c5e657a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Sun, 24 Nov 2024 22:47:16 +0200 Subject: [PATCH] infra: cache embeds (#99) --- terraform/cloudfront.tf | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/terraform/cloudfront.tf b/terraform/cloudfront.tf index 31efd7e..0e58b3d 100644 --- a/terraform/cloudfront.tf +++ b/terraform/cloudfront.tf @@ -46,6 +46,23 @@ resource "aws_cloudfront_distribution" "main" { } } + # Embed + ordered_cache_behavior { + path_pattern = "/embed/*" + allowed_methods = ["GET", "HEAD", "OPTIONS"] + cached_methods = ["GET", "HEAD", "OPTIONS"] + target_origin_id = aws_lb.main.dns_name + cache_policy_id = aws_cloudfront_cache_policy.default.id + origin_request_policy_id = aws_cloudfront_origin_request_policy.default.id + viewer_protocol_policy = "redirect-to-https" + compress = true + + function_association { + event_type = "viewer-request" + function_arn = aws_cloudfront_function.www_redirect.arn + } + } + # Media ordered_cache_behavior { path_pattern = "/media/*" @@ -97,9 +114,9 @@ resource "aws_cloudfront_distribution" "main" { resource "aws_cloudfront_cache_policy" "default" { name = "${local.namespace}-cache-policy" - min_ttl = 300 - default_ttl = 300 - max_ttl = 300 + min_ttl = 60 + default_ttl = 60 + max_ttl = 60 parameters_in_cache_key_and_forwarded_to_origin { enable_accept_encoding_brotli = true