Comparing version 0.5.3 to 0.5.4
{ | ||
"name": "grunt-aws", | ||
"description": "A Grunt interface into the Amazon Node.JS SDK", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"homepage": "https://github.com/jpillora/grunt-aws", | ||
@@ -33,2 +33,3 @@ "author": { | ||
"s3", | ||
"cloudfront", | ||
"cache", | ||
@@ -35,0 +36,0 @@ "caching", |
@@ -450,7 +450,10 @@ # grunt-aws | ||
* Invalidate a list of files, up to the maximum allowed by CloudFront | ||
* Invalidate a list of files, up to the maximum allowed by CloudFront, like `/index.html` and `/pages/whatever.html` | ||
* Update CustomErrorResponses | ||
* Update OriginPath on the first origin in the distribution, other origins will stay the same | ||
* Update DefaultRootObject | ||
### Usage | ||
To invalidate the files `/index.html` and `/pages/whatever.html` | ||
A sample configuration is below. Each property must follow the requirements from the [CloudFront updateDistribution Docs](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFront.html#updateDistribution-property). | ||
@@ -471,3 +474,11 @@ ```js | ||
'/pages/whatever.html' | ||
] | ||
], | ||
customErrorResponses: [ { | ||
ErrorCode: 0, | ||
ErrorCachingMinTTL: 0, | ||
ResponseCode: 'STRING_VALUE', | ||
ResponsePagePath: 'STRING_VALUE' | ||
} ], | ||
originPath: 'STRING_VALUE', | ||
defaultRootObject: 'STRING_VALUE' | ||
} | ||
@@ -493,7 +504,21 @@ } | ||
#### `invalidations` *required* (Array) | ||
#### `invalidations` *optional* (Array) | ||
An array of strings that are each a root relative path to a file to be invalidated | ||
#### `customErrorResponses` *optional* (Array) | ||
An array of objects with the properties shown above | ||
#### `originPath` *optional* (String) | ||
A string to set the origin path for the first origin in the distribution | ||
#### `defaultRootObject` *optional* (String) | ||
A string to set the default root object for the distribution | ||
### References | ||
@@ -500,0 +525,0 @@ |
@@ -6,3 +6,3 @@ var AWS = require("aws-sdk"), | ||
module.exports = function(grunt) { | ||
//cloudfront description | ||
@@ -21,7 +21,4 @@ var DESC = "grunt-aws's cloudfront"; | ||
if(_.isEmpty(opts.distributionId)) | ||
return grunt.log.ok("No DistributionId specified"); | ||
return grunt.log.ok("No DistributionId specified"); | ||
if(_.isEmpty(opts.invalidations)) | ||
return grunt.log.ok("No invalidations specified"); | ||
//mark as async | ||
@@ -39,8 +36,14 @@ var done = this.async(); | ||
//create records defined in opts.invalidations | ||
createInvalidations(done); | ||
var subtasks = []; | ||
subtasks.push(createInvalidations); | ||
subtasks.push(createUpdates); | ||
async.series(subtasks, done); | ||
//------------------------------------------------ | ||
//create records defined in opts.invalidations | ||
function createInvalidations(callback) { | ||
if(!opts.invalidations || !opts.invalidations.length) | ||
return callback(); | ||
var params = { | ||
@@ -62,2 +65,43 @@ DistributionId: opts.distributionId, | ||
} | ||
function createUpdates(callback) { | ||
if(!opts.customErrorResponses && !opts.originPath && !opts.defaultRootObject) | ||
return callback(); | ||
cloudfront.getDistribution({ Id: opts.distributionId }, function(err, res) { | ||
if (err) { | ||
console.log(err, err.stack); | ||
return callback(err); | ||
} | ||
var params = { | ||
Id: opts.distributionId, | ||
DistributionConfig: res.Distribution.DistributionConfig, | ||
IfMatch: res.ETag | ||
}; | ||
if(opts.customErrorResponses){ | ||
params.DistributionConfig.CustomErrorResponses = { | ||
Quantity: opts.customErrorResponses.length, | ||
Items: opts.customErrorResponses | ||
}; | ||
} | ||
if(opts.originPath){ | ||
params.DistributionConfig.Origins.Items[ 0 ].OriginPath = opts.originPath; | ||
} | ||
if(opts.defaultRootObject){ | ||
params.DistributionConfig.DefaultRootObject = opts.defaultRootObject; | ||
} | ||
cloudfront.updateDistribution(params, function(err, data) { | ||
if (err) console.log(err, err.stack); | ||
else console.log(data); | ||
callback(err); | ||
}); | ||
}); | ||
} | ||
}); | ||
@@ -64,0 +108,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37018
655
553