This example shows how to use Lambda Web Adapter to run a server side rendered Sveltekit application on the managed nodejs runtime.
Add the Lambda Web Adapter layer to the function and configure the wrapper script.
- attach Lambda Adapter layer to your function. This layer containers Lambda Adapter binary and a wrapper script.
- x86_64:
arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:24
- arm64:
arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerArm64:24
- x86_64:
- configure Lambda environment variable
AWS_LAMBDA_EXEC_WRAPPER
to/opt/bootstrap
. This is a wrapper script included in the layer. - set function handler to a startup command:
run.sh
. The wrapper script will execute this command to boot up your application.
To get more information of Wrapper script, please read Lambda documentation here.
* this example was created from the steps in this section. repeating them is not required
-
npx sv create app
- select
SvelteKit minimal
option - select
Yes, using Typescript syntax
option - repeatedly select enter to complete sveltekit install with default options
- select
-
cd app
to switch current working directory to newly createdapp
directory:npm install --save-dev @sveltejs/adapter-node
to install sveltekit node adapternpm uninstall @sveltejs/adapter-auto
to remove unused auto adapter- replace
import adapter from '@sveltejs/adapter-auto';
withimport adapter from '@sveltejs/adapter-node';
insvelte.config.js
- add a
run.sh
wrapper script:
cat << EOF > ./run.sh #!/bin/bash node index.js EOF
Run the following commands to build and deploy the application to lambda.
sam build --use-container
sam deploy --guided
When the deployment completes, take note of the SvelteKitSsrFunctionUrlEndpoint output value. This is the function URL.
Open function's URL in a browser to display the "Welcome to SvelteKit" page.