Created
October 21, 2013 12:18
-
-
Save clarkdave/7082950 to your computer and use it in GitHub Desktop.
Create an AWS Cloudfront invalidation in a Grunt task
This file contains hidden or 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
| 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