Updating X-Clacks-Overhead: GNU Terry Pratchett
By jjm
Updating my previous post X-Clacks-Overhead: GNU Terry Pratchett from 2020 about adding a custom header so that:
“A man is not dead while his name is still spoken.” - Going Postal, Chapter 4 prologue
It’s been possible to set this HTTP Header via a Response headers policy for sometime now, so instead of needing to use a Lambda@Edge function. Which has the added bonus of being free!
This is way simpler than the previous method, now you just need to add the following aws_cloudfront_response_headers_policy resource:
resource "aws_cloudfront_response_headers_policy" "this" {
name = "x-clacks-overhead"
comment = "https://xclacksoverhead.org/home/about"
custom_headers_config {
items {
header = "X-Clacks-Overhead"
override = true
value = "GNU Terry Pratchett"
}
}
}
and then reference it as follows:
resource "aws_cloudfront_distribution" "this" {
default_cache_behavior {
# Loads of stuff removed!
response_headers_policy_id = aws_cloudfront_response_headers_policy.this.id
}
# Loads of stuff deleted ....
}
It’s then really simple to test.
$ curl -I https://www.geeky-and-blonde.me.uk/
x-clacks-overhead: GNU Terry Pratchett
You can also use the same resource to add Security and CORS headers too.