aghadiry / serverless-cloudfront-invalidate

Serverless plugin that allows you to invalidate Cloudfront Cache
MIT License
29 stars 22 forks source link

Can we have an option to conditionally disable or enable this plugin? #7

Open forabi opened 6 years ago

forabi commented 6 years ago

I sometimes want to invalidate the cache only if the CI is deploying from the master branch. It would be convenient to be able to disable this plugin conditionally.

I can take a stab at this :smiley:

coyoteecd commented 4 years ago

@aghadiry are you maintaining this project? I also need an "enabled" property; assuming I submit a pull request, will you merge and publish it?

mihaerzen commented 3 years ago

I've added a PR that might help you with this. https://github.com/aghadiry/serverless-cloudfront-invalidate/pull/21

With this PR you could disable the autoInvalidate and in your CI pipeline invoke the serverless cloudfrontInvalidate where required.

Ingordigia commented 3 years ago

@mihaerzen I just added this plugin to my serverless project but the autoInvalidate flag doesn't seems to work to me.

My configuration is:

cloudfrontInvalidate:
    - distributionIdKey: "CDNDistributionId" #conditional, distributionId or distributionIdKey is required.
      autoInvalidate: false # Can be set to false to avoid automatic invalidation after the deployment. Useful if you want to manually trigger the invalidation later. Defaults to true.
      items: # one or more paths required
        - "/*"

But the deploy pipeline is still invalidating twice.

Looking into the code i'm wondering if this line is correct https://github.com/aghadiry/serverless-cloudfront-invalidate/blob/581b8f8c57e569bc4adaf0a009a1f4e4f67bbf68/index.js#L44 because autoInvalidate is not an attribute of cloudfrontInvalidate but is an attribute of every element of the list.

Am I wrong ?

mihaerzen commented 3 years ago

@Ingordigia Yes, you are correct. It was broken via https://github.com/aghadiry/serverless-cloudfront-invalidate/pull/19 .

I've made a PR which should fix this https://github.com/aghadiry/serverless-cloudfront-invalidate/pull/24

mihaerzen commented 3 years ago

@Ingordigia the PR #24 was merged and I've tested it on production Today. I found there is a small issue with it, basically, manual invalidation doesn't work anymore. Meaning if you were to invoke serverless cloudfrontInvalidate it would skip the elements with autoInvalidate: false. I've already submitted a fix with #25. Yikes 😬

Ingordigia commented 3 years ago

@mihaerzen thank you for your efforts. I just tested the version 1.10.0 in my project and I can confirm that the manual invalidation doesn't work. I wait for #25 to be merged

Ingordigia commented 3 years ago

@mihaerzen I just tested the new 1.11.0 version and it works perfectly.