Skip to content

Instantly share code, notes, and snippets.

@ShakataGaNai
Last active September 19, 2017 22:06
Show Gist options
  • Save ShakataGaNai/94fbac3e5a24eca6eedc4acd2d877cc7 to your computer and use it in GitHub Desktop.
Save ShakataGaNai/94fbac3e5a24eca6eedc4acd2d877cc7 to your computer and use it in GitHub Desktop.
A quick demonstration of using Lamba@Edge to inject extra HTTP Security/Cache Headers
'use strict';
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
var hr = {
'Strict-Transport-Security': 'max-age=600;',
'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma': 'no-cache',
'X-LambdaAtEdge': 'true'
};
for (var key in hr){
headers[key.toLowerCase()] = [
{ key: key, value: hr[key]}
];
}
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment