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

chore: add CloudFront cache invalidation for Static Site services #5035

Merged
merged 9 commits into from
Jul 7, 2023

Conversation

huanjani
Copy link
Contributor

@huanjani huanjani commented Jun 29, 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 by changing TTL values or the cache policy. Instead, we can allow the caching but invalidate the cache 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. 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 huanjani requested a review from a team as a code owner June 29, 2023 22:06
@huanjani huanjani requested review from dannyrandall and removed request for a team June 29, 2023 22:06
@github-actions
Copy link

github-actions bot commented Jun 29, 2023

🍕 Here are the new binary sizes!

Name New size (kiB) size (kiB) Delta (%)
macOS (amd) 51152 50748 +0.80
macOS (arm) 51336 50956 +0.75
linux (amd) 45032 44680 +0.79
linux (arm) 43332 43012 +0.74
windows (amd) 41872 41548 +0.78

@codecov-commenter
Copy link

codecov-commenter commented Jun 30, 2023

Codecov Report

Merging #5035 (751910b) into mainline (f111d1b) will decrease coverage by 0.03%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##           mainline    #5035      +/-   ##
============================================
- Coverage     70.00%   69.97%   -0.03%     
============================================
  Files           291      291              
  Lines         42240    42321      +81     
  Branches        285      285              
============================================
+ Hits          29569    29615      +46     
- Misses        11236    11269      +33     
- Partials       1435     1437       +2     

see 9 files with indirect coverage changes

Copy link
Contributor

@dannyrandall dannyrandall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!!

@mergify mergify bot merged commit 11e2a04 into aws:mainline Jul 7, 2023
@huanjani huanjani deleted the cf-cache-invalidation branch July 17, 2023 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalidate CF distribution on deploy of static site
4 participants