How can i set cookies in the AWS Cloudfront Module i cant find anything in the offical Documentation from AWS Terraform Module
module "cdn" {
source = "terraform-aws-modules/cloudfront/aws"
ordered_cache_behavior = [
{
path_pattern = "/wp-admin/*"
target_origin_id = "loadbalancer"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"]
headers = ["*"]
forward_cookies = "all"
compress = true
query_string = true
},
{
path_pattern = "/wp-login.php/"
target_origin_id = "loadbalancer"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"]
headers = ["*"]
forward_cookies = "all"
compress = true
query_string = true
}
]
i tryed diffrent approches like set
cookies[*]
forward_cookies = "all"
forwarded_values {
query_string = false
headers = ["Origin"]
cookies {
forward = "all"
}
}
When i run it i dont get any error but it set in Cloudfront anything to none. The same happens when i try to set any cookies. Did someone have a Solution to the Problem or should i use the offical ressources.
2
Answers
Looking at the source code, it appears you need to specify
cookies_forward = "all"
, instead offorward_cookies
. Like this:Rather than using a
cookies_forward = "all"
attribute, you could use a Cache Policy specifying not to cache cookies.To achieve that, you could either use one of the default cache policies provided by AWS like this:
And then set it within one of your
ordered_cache_behavior
blocks like this:Or you can create your own, like this:
And then set it within one of your
ordered_cache_behavior
blocks like this:Further reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html