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).
The following code example shows how to add a cache control header to a CloudFront Functions viewer response event.
- JavaScript
-
- JavaScript runtime 2.0 for CloudFront Functions
-
async function handler(event) {
var response = event.response;
var headers = response.headers;
if (response.statusCode >= 200 && response.statusCode < 400) {
// Set the cache-control header
headers['cache-control'] = {value: 'public, max-age=63072000'};
}
// Return response to viewers
return response;
}
For a complete list of Amazon SDK developer guides and code examples, see
Using CloudFront with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.