Created
August 14, 2020 22:10
-
-
Save alfredlucero/9a4b1a7a3987119a29a213d7c51d4c8c to your computer and use it in GitHub Desktop.
Security Headers Terraform - CloudFront Module Cache Behavior Lambda Function Association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ...S3 resources/policies | |
resource "aws_cloudfront_distribution" "cloudfront-distribution" { | |
# ...S3 origin configs | |
default_cache_behavior { | |
allowed_methods = ["GET", "HEAD", "OPTIONS"] | |
cached_methods = ["GET", "HEAD", "OPTIONS"] | |
target_origin_id = "${var.origin_group_id}" | |
compress = true | |
forwarded_values { | |
cookies { | |
forward = "none" | |
} | |
query_string = false | |
} | |
viewer_protocol_policy = "redirect-to-https" | |
min_ttl = 0 | |
default_ttl = 3600 | |
max_ttl = 86400 | |
# This is how we associate the Lambda@Edge function for a cache behavior | |
# and we repeat this for the other "ordered_cache_behavior" configurations | |
lambda_function_association { | |
event_type = "origin-response" | |
lambda_arn = "${aws_lambda_function.edge_security_headers_lambda.qualified_arn}" | |
} | |
} | |
} | |
# ...Lambda resources/policies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment