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:25 - arm64:
arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerArm64:24
- x86_64:
- configure Lambda environment variable
AWS_LAMBDA_EXEC_WRAPPERto/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 minimaloption - select
Yes, using Typescript syntaxoption - repeatedly select enter to complete sveltekit install with default options
- select
-
cd appto switch current working directory to newly createdappdirectory:npm install --save-dev @sveltejs/adapter-nodeto install sveltekit node adapternpm uninstall @sveltejs/adapter-autoto remove unused auto adapter- replace
import adapter from '@sveltejs/adapter-auto';withimport adapter from '@sveltejs/adapter-node';insvelte.config.js - add a
run.shwrapper 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 --guidedWhen 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.