juranki / sveltekit-cdk

Tools for deploying SvelteKit to AWS using CDK
https://juranki.github.io/sveltekit-cdk/
MIT License
31 stars 5 forks source link

Specific deployment configuration question #5

Closed KayoticSully closed 2 years ago

KayoticSully commented 2 years ago

I have spent some time updating this package to work with the latest version of sveltekit since some things were not working out of the box. I do plan to open a PR to contribute this back. However, I have hit a bit of an issue with how I want to deploy this app. Before I go and re-invent the wheel I figured I would ask to see if this is possible as this library stands. Or if I will need to make some modifications.

I am trying to get a deployment setup similar to this image (minus the Blog API Gateway stuff). In short: I want all static assets and pre-rendered pages to be served directly from CloudFront via the S3 bucket without any lambda, edge or normal, involved. And I only want to call the lambda for sveltekit "endpoints" or pages that are not configured for pre-render.

Deployment Layout

Questions

Thanks for the initial work on this library! Its already saved me a bunch of time, I'm just trying to optimize things now.

juranki commented 2 years ago

I have spent some time updating this package to work with the latest version of sveltekit since some things were not working out of the box. I do plan to open a PR to contribute this back.

Awesome!! Thank you!!

Is something like this possible as this library stands or do I have some work to do to add that configuration?

SvelteDistribution construct should be able to produce something that is quite close.

For example this construct (from https://github.com/juranki/sveltekit-cdk/blob/main/packages/constructs/src/simple-stack.ts)

        new SvelteDistribution(this, 'svelteDistribution', {
            renderer: {
                type: 'VIEWER_REQ',
                rendererProps: {
                    environment: {
                        LOG_LEVEL: 'DEBUG',
                    },
                }
            }
        })

Should produce something like this Untitled Diagram drawio

With renderer prop you can control what kind of SSR handler you want to deploy. If you want the SSR-handler to be a regular lambda behind API Gateway, renderer.type should be HTTP_ORIGIN, and renderer.endpoint should be defined.

SvelteApiV2LambdaRenderer construct produces an API Gateway - SSR lambda combo that you can assign to renderer.endpointprop of the distribution.

If this library does not handle this use-case and I manage to get it working, would you like me to contribute that back or just the baseline updates to get this working with the current latest version of sveltekit?

I think this use case is well within the desired scope of this project.

KayoticSully commented 2 years ago

Thank you for the feedback! And I think I jumped to some conclusions a bit quickly on that example distribution setup you pointed to. I had not configured the pages with export const prerender = true; so they were always going to the lambda initially. I am new to SvelteKit as well, but it is quickly becoming a favorite framework of mine.

I opened a PR with my updates if you are interested in pulling them in. Thank you again for all of this initial work. It saved me a bunch of time.