sveltekit-adapter-lambda Svelte Themes

Sveltekit Adapter Lambda

An adapter to build a SvelteKit app into a lambda ready for deployment with lambda proxy via the Serverless Framework or CDK.

adapter-lambda for SvelteKit

An adapter to build a SvelteKit app into a lambda ready for deployment with lambda proxy via the Serverless framework or CDK.

Installation

npm install --save-dev @yarbsemaj/adapter-lambda

Usage

In your svelte.config.js configure the adapter as below;

import serverless from '@yarbsemaj/adapter-lambda';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: vitePreprocess(),

    kit: {
        adapter: serverless() //See Below for optional arguments
    }
};

export default config;

For serverless

Copy serverless.yml from the root of this repo to the root of your project, make sure to change the service name.

After building your app run sls deploy to deploy code to AWS using the build tool serverless.

An example project using serverless can be found here.

For CDK

Copy SvelteKitSite.ts from the root of this repo into your project and add it to a CDK stack.

Deploy your stack using cdk deploy --all

An example project using cdk can be found here.

Tada 🎉

No matter how you deploy, your app can then be accessed via the CloudFront distribution created as a part of the stack.

Options

Argument Description Type Default
out the output directory of build files string build
esbuildOverride overrides for the default esbuild options esbuild Build Options {}

Static Assets and precompiled pages

To server static assets and precompiled pages, this adapter makes use of S3. In order to route traffic to the correct destination a Lambda@edge function is used to perform an origin rewrite to redirect traffic to the S3 Bucket.

Infrastructure Diagram

Help! I'm getting an error while building or serving my app.

Please raise an issue on Github, and I will be happy to issue a fix.

Versions

Adapter Version Sveltekit Version
1.1.x - 1.2.x 1.22.0 (Official)
1.x.x 1.0.0 (Official)
0.12.x 1.0.0-next.433
0.11.x 1.0.0-next.401
0.10.x 1.0.0-next.380
0.9.x 1.0.0-next.348
0.6.x - 0.8.x 1.0.0-next.301
0.5.x 1.0.0-next.286
0.3.x - 0.4.x 1.0.0-next.286
0.2.x 1.0.0-next.239
0.1.x 1.0.0-next.169

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes