githubEdit

8474005213__how-do-i-configure-cloudfront-referrer-policy-using-terraform

How do I configure CloudFront referrer policy using Terraform?

Context When HTTP POST requests are being rejected with status 431 due to large "Referrer" header fields, you may need to update the CloudFront referrer policy to "origin". This can be accomplished using Terraform by creating a custom response headers policy and linking it to your CloudFront distribution. Answer To configure a CloudFront referrer policy using Terraform, follow these steps: Create a custom response headers policy using the AWS CloudFront response headers policy resource: resource "aws_cloudfront_response_headers_policy" "my_policy" { name = "referrer-policy" comment = "Referrer policy set to origin" security_headers_config { referrer_policy { referrer_policy = "origin" override = true } } } Link the policy to your CloudFront distribution by using the policy ID in either the default_cache_behavior or ordered_cache_behavior configuration: resource "duplocloud_aws_cloudfront_distribution" "distribution" {

... other configuration ...

default_cache_behavior {

... other behavior settings ...

response_headers_policy_id = aws_cloudfront_response_headers_policy.my_policy.id } } Sources: AWS CloudFormation Documentation - ReferrerPolicy Terraform AWS Provider - CloudFront Response Headers Policy

Last updated

Was this helpful?