-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var AWS = require("aws-sdk"), | ||
_ = require("lodash"), | ||
async = require("async"); | ||
|
||
module.exports = function(grunt) { | ||
|
||
//cloudfront description | ||
var DESC = "grunt-aws's cloudfront"; | ||
|
||
//cloudfront defaults (none at the moment) | ||
var DEFAULTS = {}; | ||
|
||
//cloudfront task | ||
grunt.registerTask("cloudfront", DESC, function() { | ||
|
||
//get options | ||
var opts = this.options(DEFAULTS); | ||
|
||
if(_.isEmpty(opts.distributionId)) | ||
return grunt.log.ok("No DistributionId specified"); | ||
|
||
if(_.isEmpty(opts.invalidations)) | ||
return grunt.log.ok("No invalidations specified"); | ||
|
||
//mark as async | ||
var done = this.async(); | ||
|
||
//whitelist allowed keys | ||
AWS.config.update(_.pick(opts, | ||
'accessKeyId', | ||
'secretAccessKey' | ||
), true); | ||
|
||
//cloudfront client | ||
var cloudfront = new AWS.CloudFront(); | ||
|
||
//create records defined in opts.invalidations | ||
createInvalidations(done); | ||
|
||
//------------------------------------------------ | ||
|
||
function createInvalidations(callback) { | ||
var params = { | ||
DistributionId: opts.distributionId, | ||
InvalidationBatch: { | ||
CallerReference: Date.now().toString(), | ||
Paths: { | ||
Quantity: opts.invalidations.length, | ||
Items: opts.invalidations | ||
} | ||
} | ||
}; | ||
cloudfront.createInvalidation(params, function(err, data) { | ||
if (err) console.log(err, err.stack); | ||
else console.log(data); | ||
callback(err); | ||
}); | ||
} | ||
}); | ||
|
||
|
||
}; |