AWS CloudFront Setup

The following screenshots illustrate how to configure AWS CloudFront to deliver AEM content. Essential settings are marked with a red circle.

Create a CloudFront distribution

Configure the origin

If you have successfully configured push invalidation for your project you should also add the following custom header:

Cache behavior

Create cache policy

Create origin request policy

Create Function to remove Age and X-Robots-Tag headers

Go to Functions and click on “Create Function”:

Enter a name for the function (e.g. stripHeaders), an optional description and click on “Create Function”:

Replace the code of the function with the following snippet and click on “Save changes”:

function handler(event) {
    const response = event.response;
    const request = event.request;
    const headers = response.headers;

    // Strip age header
    delete headers['age'];

    // Check if the request URL does not end with '.plain.html'
    if (!request.uri.endsWith('.plain.html')) {
        delete headers['x-robots-tag'];

    return response;

Click on “Publish function”:

Finally, associate the function with your distribution:

That’s all (more or less). Please test the distribution in a stage environment.