Open juranki opened 2 years ago
Hey @juranki I'm trying to dig into your project and to understand what's happening :)
I understand that you use one Lambda@Edge function whose handler imports the whole SvelteKit app, does SSR when necessary, otherwise just instructs CloudFront to provide the pre-rendered page.
Could you please help to understand
Thanks! And please keep up the good work!
This is the only AWS adapter working with the latest sveltekit version out in the wild - afaik. Cool!
I understand that you use one Lambda@Edge function whose handler imports the whole SvelteKit app, does SSR when necessary, otherwise just instructs CloudFront to provide the pre-rendered page.
Correct.
why did you chose Lambda@Edge over API Gateway + {proxy+} + regular Lambda pattern? Isn't there a risk that the code reaches the Lamda@Edge quotas?
The primary reason is the mechanism Lambda@Edge provides for handling pre-rendered pages. Secondary reasons include simplicity and less network hops, thus potentially smaller latency (haven't measured though)
There is a potential for hitting the quotas. The relevant ones are response size (1 MB) and compressed size of the handler (50 MB). For most use cases those should be reasonable, although it's easy to come up with cases that could be problematic.
Isn't it considered best practice to have many small functions?
With many small functions you can possibly reduce startup time and avoid function size quota, but at the same time the number of cold starts increases. Pick your poison :)
Is this exactly the topic of this issue, to split the application into several lambdas?
Yes, and currently I think this is in some-day-maybe category. The complexity is significant and I'm not sure if it's possible to map SvelteKit routes to CloudFront behaviour patterns.
Great work on this. I'm still trying to learn Sveltekit and dive deeper into CDK, so take my points with this in mind. I am starting at the end (i.e. deployment) because this has become my natural way of thinking.
Server
, so can you elaborate more on that?Hello @aihaddad,
Thank you @juranki
Regarding point 2, Lambda@Edge is definitely the better/best/only option for pre-rendered static and client pages, I was referring more to SSR. Basically everything beyond line 38 (as far as I understand) where it can probably be delegated to another Lambda, and that's the one where the choice can be given
https://github.com/sveltejs/kit/pull/2931