
Welcome 2026 AWS Summit Toronto attendee!
Please leave a review for my session within the AWS Events application as soon as you get a moment.
Links
Posts on relevant topics:
- Simplest explanation of the 6 CloudFront Caching expiration (Time to Live/TTL) scenarios with 7 useful tips
- AWS CloudFront Standard Logging v2 to S3 Bucket with CloudFormation example
- URL Redirects on Amazon Web Services with CloudFront and S3
CloudFront Function – WordPress Cache Buster
The following CloudFront function is an example how you can use a special HTTP header to “bust” through the CloudFront cache. The HTTP header you use should be part of the Cache policy’s headers to work.
/*
* CloudFront request function - WordPress Cache Buster for signed in users
*/
const busterHeader = 'x-cache-buster'; // This header is added to the CloudFront cache key Policy
async function handler(event) {
var request = event.request;
// Accessing a cookie value
if (request.cookies) {
var cookies = request.cookies;
Object.keys(cookies).forEach(key => {
if( key.startsWith('wordpress_logged_in_') ) { // Generate a random UUID v4 string
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
request.headers[busterHeader] = {value: uuid };
return request;
}
});
}
return request;
}
// eof
Looking for more?
Browse my archive of Amazon Web Services posts for even more helpful content.