Add a Cache-Control header to the response - Amazon CloudFront
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Add a Cache-Control header to the response

The following example function adds a Cache-Control HTTP header to the response. The header uses the max-age directive to tell web browsers to cache the response for a maximum of two years (63,072,000 seconds). For more information, see Cache-Control on the MDN Web Docs website.

This is a viewer response function.

See this example on GitHub.

JavaScript runtime 2.0
async function handler(event) { const response = event.response; const headers = response.headers; // Set the cache-control header headers['cache-control'] = {value: 'public, max-age=63072000'}; // Return response to viewers return response; }
JavaScript runtime 1.0
function handler(event) { var response = event.response; var headers = response.headers; // Set the cache-control header headers['cache-control'] = {value: 'public, max-age=63072000'}; // Return response to viewers return response; }