Skip to content

Instantly share code, notes, and snippets.

@clarkdave
Created October 21, 2013 12:18
Show Gist options
  • Select an option

  • Save clarkdave/7082950 to your computer and use it in GitHub Desktop.

Select an option

Save clarkdave/7082950 to your computer and use it in GitHub Desktop.
Create an AWS Cloudfront invalidation in a Grunt task
grunt.registerTask('cloudfront:invalidate', 'invalidate lib on cloudfront', function() {
var finished = this.async(),
aws = require('aws-sdk'),
path = '/libs/ll.sdk-' + sdk_version + '.js'
;
// set aws keys & region from config
aws.config.update({
accessKeyId: config.aws.accessKeyId,
secretAccessKey: config.aws.secretAccessKey,
// CloudFront doesn't use regions, but unless this is set to us-east-1
// the API will cry and refuse to do anything
region: 'us-east-1'
});
var cloudfront = new aws.CloudFront({ apiVersion: '2013-05-12' });
cloudfront.createInvalidation({
DistributionId: config.aws_cloudfront_distribution,
InvalidationBatch: {
Paths: {
Quantity: 1,
Items: [
path
]
},
CallerReference: new Date().getTime().toString()
}
}, function(err, data) {
if (err) {
grunt.log.error('Failed');
grunt.log.errorlns(err.message);
finished();
} else {
grunt.log.ok('Invalidation created (id: ' + data.Id + ')');
finished();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment