diff --git a/infrastructure/terraform/modules/cloudfront/main.tf b/infrastructure/terraform/modules/cloudfront/main.tf index d73edadc..1b68b891 100644 --- a/infrastructure/terraform/modules/cloudfront/main.tf +++ b/infrastructure/terraform/modules/cloudfront/main.tf @@ -46,23 +46,47 @@ resource "aws_cloudfront_distribution" "this" { aliases = var.aliases ########################################## - # Default Cache Behavior + # Default Cache Behavior (S3) ########################################## default_cache_behavior { - target_origin_id = var.origins[0].origin_id + target_origin_id = "s3-origin" + + viewer_protocol_policy = "redirect-to-https" + + allowed_methods = ["GET", "HEAD"] + cached_methods = ["GET", "HEAD"] + + forwarded_values { + query_string = false + + cookies { + forward = "none" + } + } + + compress = true + min_ttl = 0 + default_ttl = 3600 + max_ttl = 86400 + } + + ########################################## + # API Behavior + ########################################## + + ordered_cache_behavior { + path_pattern = "/v1/*" + target_origin_id = "api-origin" viewer_protocol_policy = "redirect-to-https" allowed_methods = [ - "GET", - "HEAD" + "GET","HEAD","OPTIONS", + "PUT","POST","PATCH","DELETE" ] - cached_methods = [ - "GET", - "HEAD" - ] + cached_methods = ["GET","HEAD"] forwarded_values { query_string = true @@ -73,10 +97,9 @@ resource "aws_cloudfront_distribution" "this" { } } - compress = true - min_ttl = 0 - default_ttl = 3600 - max_ttl = 86400 + min_ttl = 0 + default_ttl = 0 + max_ttl = 0 } price_class = "PriceClass_All"