Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate CF distribution on deploy of static site #5024

Closed
yannickvr opened this issue Jun 26, 2023 · 5 comments · Fixed by #5035
Closed

Invalidate CF distribution on deploy of static site #5024

yannickvr opened this issue Jun 26, 2023 · 5 comments · Fixed by #5035
Labels
type/request Issues that are created by customers.

Comments

@yannickvr
Copy link

yannickvr commented Jun 26, 2023

The Static Site Service does currently not invalidate existing assets on the cloudfront distribution when redeploying the service, so e.g. when index.html is updated to add a new menu item, it's not immediately visible.

I think there should be an invalidations option for the static site service, e.g.

name: static-site
type: Static Site
files:
  - source: source
    recursive: true
    invalidations:
        - index.html
@huanjani
Copy link
Contributor

Hi, @yannickvr.
Thanks for the feedback! We're actually working on cache validation currently. Our plan is to invalidate any cached files upon deployment by default. Do you feel strongly that users should have the ability to specify files for invalidation and that all files shouldn't be invalidated by default?

@huanjani huanjani added type/enhancement Issues that are improvements for existing features. type/request Issues that are created by customers. and removed type/enhancement Issues that are improvements for existing features. labels Jun 26, 2023
@yannickvr
Copy link
Author

Hi, @yannickvr. Thanks for the feedback! We're actually working on cache validation currently. Our plan is to invalidate any cached files upon deployment by default. Do you feel strongly that users should have the ability to specify files for invalidation and that all files shouldn't be invalidated by default?

I would argue that invalidating all by default would be good standard behavior, but an option to exclude/include certain files/folders could be high on the wishlist. E.g. I would normally be fine with my /pictures folder not validating every deployment, as it could contain thousands of pictures that are normally only added and never changed, but my earlier example of indexes etc. I would want to do every deploy, as they would change over their livecycle

@iamhopaul123
Copy link
Contributor

Hello @yannickvr.

but an option to exclude/include certain files/folders could be high on the wishlist.

Basically if we support doing invalidation by default after each deployment, you would want to exclude certain files/folders because very likely they won't change and doing invalidation for them will lead to extra invalidation time?

@yannickvr
Copy link
Author

Hello @yannickvr.

but an option to exclude/include certain files/folders could be high on the wishlist.

Basically if we support doing invalidation by default after each deployment, you would want to exclude certain files/folders because very likely they won't change and doing invalidation for them will lead to extra invalidation time?

Exactly, though doing some research, I'm not completely sure if that makes sense. It seems that a wildcard invalidation /* would count as a single path and be billed as such (1000 invalidations free/mo and then $0.005 per invalidation), that would suggest a wildcard invalidation would be faster then invalidating specific paths as well.

@mergify mergify bot closed this as completed in #5035 Jul 7, 2023
mergify bot pushed a commit that referenced this issue Jul 7, 2023
)

One of the ways in which CloudFront reduces latency is by caching objects at edge locations, reducing the number of requests that users’ origin servers must respond to directly. For Copilot-managed Static Site services, this caching behavior has the unfortunate side effect of redeployments using cached— and out-of-date— versions of source files. By default, files expire after 24 hours.

We want users to benefit from edge caches, so we don’t want to [manage cache expiration](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html) by changing TTL values or the [cache policy](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html). Instead, we can allow the caching but [invalidate the cache](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html) each time the Static Site service is redeployed, after (updated) files are uploaded. This way, the updated files are served from the origin server rather than the outdated cached files.

We opted to invalidate all files (`/*`) for simplicity, efficiency, and [cost-savings](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#PayingForInvalidation). If, in the future, customers request the ability to exclude files from invalidation, we can consider adding that config to the workload manifest.

Resolves: #5024.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
@huanjani
Copy link
Contributor

This enhancement has now been released in v1.29.0: https://github.com/aws/copilot-cli/releases/tag/v1.29.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/request Issues that are created by customers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants