Created
November 15, 2018 15:00
-
-
Save guilhermevini/6af868db2a68d1f53795d8833fe0b149 to your computer and use it in GitHub Desktop.
Lambda function to invalidate cloudfront cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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