-
Notifications
You must be signed in to change notification settings - Fork 78
/
invalidate.cloudfront.js
35 lines (32 loc) · 1.13 KB
/
invalidate.cloudfront.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const exec = require('child_process').exec;
const colors = require('colors');
const AWS = require('aws-sdk');
const cloudfront = new AWS.CloudFront();
const pathToInvalidate = `/searchui/v${process.env.MAJOR_MINOR_VERSION}/*`;
const invalidationRequest = cloudfront.createInvalidation({
DistributionId: 'E2VWLFSCSD1GLA',
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: 1,
Items: [pathToInvalidate]
}
}
});
invalidationRequest.send((error, success) => {
if (error) {
console.log(colors.red('ERROR WHILE INVALIDATING RESSOURCES ON CLOUDFRONT'));
console.log(colors.red('*************'));
console.log(colors.red(error.message));
console.log(colors.red('*************'));
exec('travis_terminate 1');
throw error;
}
if (success) {
console.log(colors.green('INVALIDATION ON CLOUDFRONT SUCCESSFUL'));
console.log(colors.green('*************'));
console.log(colors.green(`PATH INVALIDATED: ${pathToInvalidate}`));
console.log(colors.green(`INVALIDATION ID : ${success.Invalidation.Id}`));
console.log(colors.green('*************'));
}
});