Skip to content

Instantly share code, notes, and snippets.

@colbyfayock
Created June 10, 2018 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colbyfayock/1e991948fedc8303ae14bda03dea9e3d to your computer and use it in GitHub Desktop.
Save colbyfayock/1e991948fedc8303ae14bda03dea9e3d to your computer and use it in GitHub Desktop.
Invalidate Cloudfront Cache from aws_s3 output in Grunt
// Pulls in the changed files from aws_s3 at run time and pass them
// into cloudfront invalidation
grunt.registerTask('invalidate_cache', 'Invalidate Cloudfront from aws_s3 output', function (subtask) {
var aws_changed = grunt.config.get('aws_s3_changed'),
task = 'cloudfront',
changed_files;
if ( !Array.isArray(aws_changed) ) {
console.log('Changed files is not an array');
return;
}
changed_files = aws_changed.map(function(file) {
return '/' + file;
});
if ( subtask ) {
task = task + ':' + subtask;
}
grunt.config.set('cloudfront.options.invalidations', changed_files);
if ( !Array.isArray(changed_files) || changed_files.length === 0 ) {
console.log('No files changed');
return;
}
grunt.task.run(task);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment