![stability-alpha](https://img.shields.io/badge/stability-alpha-f4d03f.svg)
![Release](https://github.com/Data-Only-Greater/sveltekit-adapter-aws-pulumi/actions/workflows/release.yml/badge.svg)
![codecov](https://codecov.io/github/Data-Only-Greater/sveltekit-adapter-aws-pulumi/branch/main/graph/badge.svg?token=LIENVYALUL)
SvelteKit AWS Adapter for Pulumi
This project contains a SvelteKit adapter to deploy SvelteKit to AWS using
Pulumi.
How to use?
Setup
- Ensure that the Pulumi CLI is installed.
- Create a SvelteKit project "my-app" -
npm create svelte@latest my-app
cd my-app
npm install
npm install -D sveltekit-adapter-aws-pulumi
- Edit svelte.config.js (see below)
- Set the following environment variables:
- PULUMI_ACCESS_TOKEN
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
Build
npm run build
Destroy
npx adapter-stack-destroy
Basic setup example
svelte.config.js
import { adapter } from 'sveltekit-adapter-aws-pulumi'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter({
autoDeploy: true,
}),
},
}
export default config
Architecture
The following diagram shows the architecture deployed by this package. The key
features are as follows:
- A CloudFront CDN
- An S3 bucket to serve prerendered and static content (secured using OAC)
- Two lambda functions with URL access (secured with AWS_IAM authentication):
- A lambda that serves the SSR code
- A lambda for OPTIONS requests used to manage preflight CORS
- A lambda@edge router that will:
- Serve static content from the S3 bucket as the cloudfront default origin
- Rewrite the cloudfront origin for requests which require SSR or use the
OPTIONS method and sign them.
![Architecture](https://github.com/Data-Only-Greater/sveltekit-adapter-aws-pulumi/raw/HEAD/architecture.svg)
Configuration
export interface AWSAdapterProps {
artifactPath?: string
autoDeploy?: boolean
defaultHeaders?: string[]
extraHeaders?: string[]
esbuildOptions?: any
FQDN?: string
memorySize?: number
pulumiPaths: string[]
region?: string
serverStreaming?: boolean
stackName?: string
}
Server Environment Variables
Variables can be included in the environment of the SSR server by defining them
in a .env
file. For example:
AUTH_SECRET=
AUTH_TRUST_HOST=
Values can be added to the .env
file or defined as environment
variables. If environment variables are defined they will overwrite the values
in the .env file.
See $env/static/private
in the SvelteKit documentation for further details.
Destroy Command
A script is provided to destroy the infrastructure, with the following
signature:
adapter-stack-destroy [artifactPath]
Destroy the SvelteKit adapter's Pulumi stacks
Positionals:
artifactPath directory containing the build artifacts. Defaults to 'build'
[string]
Options:
--version Show version number [boolean]
-s stack name [string]
--default-projects use the built-in Pulumi projects [boolean]
-f, --force cancel ongoing stack updates [boolean]
-h, --help Show help [boolean]
When running locally, adapter-stack-destroy
can be called with no arguments
and it will remove the Pulumi stacks based on a config file in the build
directory. If an alternative artifact path was used, pass this value to the
script.
When running in a stateless environment, such as CI, passing the option -s
with a stack name and --default-projects
will delete the given stack based
on the projects defined within the package.
Dependencies
This package utilises the SvelteKit AWS Adapter Base
Package to
prepare the files to be deployed. The project is seeking collaborators to
develop alternative IAC solutions. Please open an issue in the project if you
are interested in collaborating.
Credits
This package is derived from Mike Bild's adapter for CDK and
inspired by James Bray's adapter for Serverless
Framework.