Skip to content

Update cache policy to stop cookies being passed to S3 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ locals {
enable_accept_encoding_brotli = coalesce(try(var.cloudfront.cache_policy.enable_accept_encoding_brotli, null), true)
enable_accept_encoding_gzip = coalesce(try(var.cloudfront.cache_policy.enable_accept_encoding_gzip, null), true)
cookies_config = merge({
cookie_behavior = "all",
cookie_behavior = "none",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, we had the same issue where our cookies were too long which prevented assets from loading and we try overriding this via the modules. We then updated this in our fork and it still did not work. When you update cloudfront.tf , look for this snippet of code:

 ordered_cache_behavior {
    path_pattern     = "/_next/static/*"
    allowed_methods  = ["GET", "HEAD"]
    cached_methods   = ["GET", "HEAD"]
    target_origin_id = local.assets_origin_id

    response_headers_policy_id = aws_cloudfront_response_headers_policy.response_headers_policy.id
    cache_policy_id            = contains(var.no_cache_paths, "/_next/static/*") ? data.aws_cloudfront_cache_policy.no_cache.id : aws_cloudfront_cache_policy.cache_policy.id
    origin_request_policy_id = try(
      data.aws_cloudfront_origin_request_policy.origin_request_policy[0].id,
      aws_cloudfront_origin_request_policy.origin_request_policy[0].id
    )

Delete the origin_request_policy_id and re-deploy and you won't have the issue anymore. This is how I fixed it via the fork but it would be nice to be able to make this configurable via the module.

items = []
}, try(var.cloudfront.cache_policy.cookies_config, {}))
headers_config = merge({
Expand Down