Skip to content

Instantly share code, notes, and snippets.

@guilhermevini
Created November 15, 2018 15:00
Show Gist options
  • Save guilhermevini/6af868db2a68d1f53795d8833fe0b149 to your computer and use it in GitHub Desktop.
Save guilhermevini/6af868db2a68d1f53795d8833fe0b149 to your computer and use it in GitHub Desktop.
Lambda function to invalidate cloudfront cache
var AWS = require('aws-sdk');
var cloudfront = new AWS.CloudFront();
exports.handler = function (event) {
console.log(event);
const id = 'xxxx';
const currentTimeStamp = new Date().getTime();
const params = {
DistributionId: id,
InvalidationBatch: {
CallerReference: currentTimeStamp.toString(),
Paths: {
Quantity: 1,
Items: [
'/*',
]
}
}
};
cloudfront.createInvalidation(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment