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

[SsrSite]: Add function warming to all SsrSite constructs #2988

Closed
SpencerDuball opened this issue Jun 19, 2023 · 3 comments
Closed

[SsrSite]: Add function warming to all SsrSite constructs #2988

SpencerDuball opened this issue Jun 19, 2023 · 3 comments

Comments

@SpencerDuball
Copy link
Contributor

Feature Request

I want to have the option to warm functions with all SsrSite constructs similar to how we can warm function with NextjsSite construct via open-next. The specific ask is to have the SsrSite updated to accept warm: number as an option keeping the same API as NextjsSite - this would allow all other constructs such as RemixSite, SvelteKitSite, SolidStartSite, AstroSite to keep instances warm.

Overview

I was having a look at the implementation for the open-next to mimic this for RemixSite and try to get a PR pushed but there were two larger design decisions that I think warrant some discussion before pushing something.

  1. warm feature should be part of the SsrSite API
  2. The warmer function handler should be defined in sst, not as an implementation detail of the specific site you are deploying.

1. warm part of SsrSite

I was having a look at the NextjsSite to mimic this behavior and see that this warming feature is really two parts. There is a createWarmer function on the NextjsSite construct that will deploy a warmer lambda and a cron job to invoke this lambda. Then there is the actual warmer lambda (which is part of the open-next package) here.

The reason this could be generalized for all SsrSite constructs is because there is only ever one lambda for these regional deploys (maybe many instances, but only one lambda arn) which exists as this.serverLambdaForRegional. There is nothing unique about the NextjsSite that would preclude the others from using this exact same this.createWarmer function.

2. Warmer Handler in SST, not open-next

The next thought would be to have the actual warmer lambda be defined as part of SST not open-next (of any other type of site). Currently, the NextjsSite statically defines this location for the warmer lambda as .open-next/warmer-function.ts but there is also nothing unique to NextjsSite that would preclude us from making this function generic to all constructs. It should be possible to have this pre-bundled lambda be included as part of SST itself.

I would be happy to create a PR for this, the only issue I could see if that open-next is not specific to SST. Would moving this handler lambda to SST be a deal breaker for compatibility with other deploy options that open-next supports? For example, do we need to have the warmer lambda be .open-next/warmer-function.ts for any reason?

@SpencerDuball
Copy link
Contributor Author

SpencerDuball commented Jun 20, 2023

I have test deployed a RemixSite with 2 warmer functions and it has been working well, this is mostly just taking what @fwang did with the NextjsSite for function warming and applying it generally to all SsrSite constructs. One important note, when deploying NextjsSite, the .open-next/warmer-function.ts will no longer be used in SST! Can someone with knowledge of open-next confirm if this is acceptable? The warmer function is almost identical and the .open-next/warmer-function.ts and this file can be left in open-next to be used for other deployment options still if they want (cdk, tf, or whichever open-next supports).

@SpencerDuball
Copy link
Contributor Author

Good news for anyone who wants function warming right away! I created a package that is very similar to this Issue+PR , you can now use this package as a drop-in replacement for your existing RemixSite, SvelteKitSite, AstroSite, or SolidStartSite. This package exists only to bridge the gap until function warming is added to SST proper, but in the meantime I hope this is useful. I have successfully deploy my personal site with function warming (which is a RemixSite) with this new package, and the code for each site is identical: https://github.com/SpencerDuball/sst-warmer

@fwang
Copy link
Contributor

fwang commented Sep 13, 2023

Thanks @SpencerDuball! Fixed in #3301

@fwang fwang closed this as completed Sep 13, 2023
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

No branches or pull requests

2 participants