A Stacktape SvelteKit resource deploys a SvelteKit SSR app with a Lambda-based server, S3-backed static assets, and a CloudFront CDN. Use SvelteKitWeb when you want to keep the SvelteKit app model while Stacktape manages the AWS hosting shape, including custom domains, environment variables, cache controls, and optional CDN-scoped firewall protection.
When to use
Use a Stacktape SvelteKitWeb resource when your SvelteKit app needs server-side rendering or other runtime behavior that cannot be exported as static files. The resource is shaped around the standard SvelteKit project layout: Stacktape builds the app, uploads static assets, and runs SSR requests through a Lambda server function.
Common use cases:
- SSR SvelteKit apps — pages and endpoints that need request-time rendering or server-side data loading
- Monorepos — apps where the SvelteKit workspace lives below the Stacktape config and needs
appDirectory - Custom domains — public sites that need Route 53 DNS records and TLS certificates managed from Stacktape config
- Protected frontends — apps that should be protected at the CDN layer by a web application firewall
- Apps using other stack resources — frontends that need
connectToaccess to databases, buckets, queues, or auth pools
When NOT to use
A Stacktape SvelteKitWeb resource is not the best fit when the app does not need a SvelteKit SSR runtime. Static-only SvelteKit sites should use static hosting with hostingContentType: 'sveltekit-static-website', because an SSR Lambda function adds runtime behavior you are not using.
- Static-only SvelteKit output — use a
HostingBucketwithhostingContentType: 'sveltekit-static-website'via static hosting instead of deploying a server Lambda. - Non-Svelte frontend frameworks — use the dedicated resource for Next.js, Astro, Nuxt, SolidStart, TanStack Start, or Remix.
- Custom container servers — use a web-service when you want to run your own containerized HTTP server instead of the SvelteKit Lambda adapter path.
- Backend APIs without a frontend app — use a Lambda function, web-service, or HTTP API Gateway depending on the runtime shape.
Basic example
A minimal Stacktape SvelteKitWeb config points Stacktape at the directory containing svelte.config.js. If the Stacktape config file already lives at the SvelteKit app root, omit appDirectory; the default is .. In a monorepo, set appDirectory to the SvelteKit workspace directory.
The frontend resource builds the SvelteKit app from ./apps/web, uses S3 for static assets, uses CloudFront as the CDN, and configures a Lambda-based SvelteKit server.
Stacktape's Lambda packaging requires @sveltejs/adapter-node. The @sveltejs/adapter-auto used by the standard
scaffold does not emit the build/handler.js server output Stacktape deploys. Install the Node adapter and select it in
the SvelteKit app:
Stacktape validates the adapter dependency before building and reports the exact configuration requirement when the server output is missing.
Project directory
The appDirectory property tells Stacktape where the SvelteKit project lives. Stacktape expects that directory to contain svelte.config.js; for monorepos, point appDirectory at the package or workspace that owns the SvelteKit app instead of the repository root.
Keep appDirectory boring. Most teams should set it once and leave it alone. If your repository has multiple frontend apps, define one frontend resource per app so each Stacktape resource has a clear build directory, custom domain set, and runtime configuration.
Build commands
Stacktape uses vite build for SvelteKitWeb unless you override the build command. Set buildCommand when your package manager, workspace tooling, or build pipeline needs a different command, such as a workspace-scoped package script.
Set buildCommand when the default vite build command is not the command your SvelteKit workspace should run. For dev mode, the dev property customizes how stacktape dev starts the local SvelteKit dev server; when omitted, Stacktape uses vite dev.
Domains
A Stacktape SvelteKitWeb resource can attach custom domains and let Stacktape manage the DNS record and TLS certificate. The domain must have a Route 53 hosted zone in the AWS account, and the domain name should be written without the https:// protocol prefix.
For most teams, Stacktape-managed certificates are the right default. Use customCertificateArn only when you already need a specific ACM certificate, and use disableDnsRecordCreation only when another DNS provider or process owns the DNS record.
Custom domains for SvelteKitWeb require a Route 53 hosted zone in the AWS account. If your registrar is not Route 53, the registrar still needs to point the domain to the Route 53 hosted zone nameservers.
Caching and headers
SvelteKitWeb uses a CloudFront CDN in front of the SvelteKit app. The cdn property controls cache behavior for SSR routes and specific path patterns, while fileOptions sets headers such as Cache-Control for static files that match a pattern.
| Concern | Property | Use it when |
|---|---|---|
| SSR route caching | cdn | You need explicit cache controls for rendered routes or path patterns. |
| Static file headers | fileOptions | You need custom headers for uploaded static files, such as Cache-Control. |
Most SvelteKit apps should start with the default CDN behavior and add cache rules only after deciding which routes are safe to cache. Be careful with pages that depend on cookies, authorization headers, or user-specific data; caching those responses broadly can expose stale or incorrect content.
Environment and access
SvelteKitWeb environment variables are passed to the SSR Lambda function. Use environment for explicit runtime configuration, and use connectTo when the SvelteKit server needs access to other Stacktape resources such as databases, buckets, queues, topics, or auth pools.
When connectTo references another resource, Stacktape grants the needed IAM permissions, opens supported network access for databases and Redis, and injects connection variables using the STP_[RESOURCE_NAME]_[PARAM] pattern. For example, a connected relational database named mainDatabase injects STP_MAIN_DATABASE_CONNECTION_STRING, STP_MAIN_DATABASE_HOST, and STP_MAIN_DATABASE_PORT; see connecting resources for the full matrix.
When connectTo does not cover the AWS service you need — for example, calling Amazon Rekognition, Textract, or Bedrock — use iamRoleStatements to attach raw IAM policy statements to the SSR Lambda function's execution role. These statements are added alongside any permissions generated by connectTo.
Server Lambda
The serverLambda property customizes the Lambda function that handles SvelteKit SSR requests. Use it when the server side of the app needs different memory, timeout, VPC, or logging configuration than the default generated function. The SSR function inherits memory, CPU, timeout, and VPC behavior from Lambda functions.
Reach for serverLambda only when you have a concrete runtime reason: slow SSR routes, larger server-side dependencies, VPC-only dependencies, or logging requirements. Keep the default for small sites and early stages, because changing Lambda runtime settings adds operational surface without changing the SvelteKit programming model.
Security
SvelteKitWeb can attach a web application firewall at the CDN layer with useFirewall. useFirewall is the name of a separately defined web-app-firewall resource, not an inline firewall configuration. The referenced firewall must have scope: 'cdn', because SvelteKitWeb traffic is protected through CloudFront rather than an Application Load Balancer.
Use a CDN-scoped firewall for public production apps that need request filtering before traffic reaches the SSR Lambda function. Skip it for internal previews, low-risk prototypes, or apps already protected by another access layer; firewall rules add configuration and can block legitimate requests if they are too broad.
Dev mode
The dev property configures how stacktape dev starts the local SvelteKit dev server. When omitted, Stacktape defaults to vite dev. Override dev when your project uses a different dev command — for example, a workspace-scoped script or a custom Vite configuration path. Environment variables from connectTo and environment are injected into the dev server process, so server-side code can reach deployed databases and other resources during local development. See dev mode for the broader local development workflow.
SvelteKit FAQ
When should I use static hosting instead of SvelteKitWeb?
Use SvelteKitWeb when your app needs server-side rendering or runtime endpoints; it deploys a Lambda-based SvelteKit server, S3 static assets, and a CloudFront CDN. If your app can be exported as static files, use static hosting with hostingContentType: 'sveltekit-static-website' instead, which avoids deploying a server Lambda for behavior the site does not use.
Why does my custom domain fail to provision?
Custom domains for SvelteKitWeb require a Route 53 hosted zone in the AWS account. If your registrar is not Route 53, the registrar must still point the domain at the Route 53 hosted zone nameservers. Write domainName without the https:// prefix; Stacktape then creates the DNS record and provisions a TLS certificate. See custom domains for the broader model.
How do SvelteKit environment variables and database access work?
Use environment for explicit variables passed to the SSR Lambda function. Use connectTo when the SvelteKit server needs access to another Stacktape resource; a database named mainDatabase gets variables such as STP_MAIN_DATABASE_CONNECTION_STRING. See connecting resources for the injected variable pattern.
How do I protect a SvelteKit app with AWS WAF?
Set useFirewall to the name of a separately defined web application firewall resource. useFirewall takes a resource name, not an inline firewall config, and the referenced firewall must have scope: 'cdn' because SvelteKitWeb traffic is filtered through CloudFront rather than an Application Load Balancer.
How much does SvelteKit hosting on AWS cost?
A SvelteKitWeb app uses Lambda for SSR execution, S3 for static asset storage, and CloudFront for CDN delivery. AWS billing therefore depends on server invocation volume and duration, stored assets, request counts, and data transfer. Use managing costs to track deployed stack spend.
Should I use SvelteKitWeb or a web-service?
Use SvelteKitWeb when you want Stacktape to deploy the SvelteKit SSR app through the Lambda, S3, and CloudFront path described by the resource. Use a web-service when you want to run a custom containerized HTTP server and control the server process directly.
How do I configure SvelteKitWeb in a monorepo?
Set appDirectory to the directory containing the SvelteKit app's svelte.config.js, such as ./apps/web. Keep framework-specific build scripts inside that workspace, then override buildCommand only when the default vite build command is not the right command for that workspace.
Referenceable parameters
The following parameters can be easily referenced using $ResourceParam directive directive.
To learn more about referencing parameters, refer to referencing parameters.
Website URL
- Usage:
$ResourceParam('<<resource-name>>', 'url')
API Reference
SvelteKitWebProps