jpillora / grunt-aws

A Grunt interface into the Amazon Node.JS SDK
171 stars 44 forks source link

Can cloudfront task invalidation array be dynamic? #23

Open kaffolder7 opened 9 years ago

kaffolder7 commented 9 years ago

I absolutely LOVE this grunt plugin, but am really having a hard time using the cloudfront task. It appears from the documentation that the 'invalidations' array needs to have static full paths to files passed in (i.e. '/index.html', '/assets/css/main.css', etc.). However, as I'm sure you can deduce, keeping a list of every file in the project (esp. as the project grows over time) with each file being it's own line-item/string is exhaustive. I was hoping that instead, I could use some of Grunt's built-in globbing functions so that I am able to scan the entire folder tree for specific file types and invalidate those files.

Here's what I'm trying below in my Gruntfile. If anyone has any ideas, please let me know! This causes the Grunt build to fail. Not sure why I cannot use Grunt's globbing patterns. :(

cloudfront: {
    options: {
        accessKeyId: '###masked for security###',  // confirmed this is working
        secretAccessKey: '###masked for security###',  // confirmed this is working
        distributionId: '###masked for security###',  // confirmed this is working
        invalidations: [
            // Fonts
            '/assets/fonts/**/*.{eot,svg,ttf,woff,woff2}',
            // Text
            '/**/*.{txt,xml,pdf}',
            // Images
            '/assets/images/**/*.{jpg,webp,png,gif}',
            '/projects/images/**/*.{jpg,webp,png,gif}',
            // JS
            '/assets/js/**/*.{js,map}',
            // CSS
            '/assets/css/**/*.{css,map}',
            // HTML
            '/**/*.html'
        ]
    }
}
jpillora commented 9 years ago

I'm guessing globbing patterns support needs to be added, I don't actually use cloud front, @bxjx any ideas?

treasonx commented 9 years ago

Yeah I would love to be able to tell which assets were synced with the s3 task and invalidate those items. Or at the very least use the file list from the s3 sync as the invalidation list.

kaffolder7 commented 9 years ago

Any updates here anyone, or have either of you @jpillora / @treasonx figured out a viable solution that you're using until this type of globbing pattern support is added?

lukebussey commented 9 years ago

Invalidation paths can now be dynamic, so you can just do this:

options: {
    invalidations: ['/assets/fonts/*']
}

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html