npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sveltekit-adapter-aws-base

v3.0.2

Published

IAC agnostic package for deploying SvelteKit to AWS.

Downloads

52

Readme

npm stability-alpha

Unit tests Release

codecov

SvelteKit AWS Adapter Base Package

This project is for the use of SvelteKit adapters which deploy to AWS using various IAC providers. It provides functions common to a reference AWS architecture.

The project is in development and is seeking collaborators to develop implementations for IAC providers. See the examples section for the IAC providers that are currently supported. Please feel free to open an issue if you would like to discuss using or developing this package.

Installation

$ npm install sveltekit-adapter-aws-base

How to use?

This package is not intended for end-user usage. Please use one of the consumers of this package in the example IAC providers section.

For developers of AWS SvelteKit adapters that wish to implement a new IAC solution, this package provides functions for implementing the following reference architecture:

Architecture

The lambda@edge function handles origin requests from a Cloudfront CDN that has a default S3 origin for static files and two lambda function URLs for the SSR server and an OPTIONS request handler (for preflight CORS checks). The router signs requests to the lambda URLs, thus they can be configured to use AWS_IAM authentication. If the S3 origin is also secured with OAC, then all origins will only be accessible through the CDN.

The functions provided by this package implement the SSR server, options handler and lambda@edge router. They are defined as follows:

buildServer(builder, artifactPath, esbuildOptions) ⇒ Promise.<SiteProps>

Kind: global function

| Param | Type | Default | Description | | -------------- | -------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------ | | builder | any | | The SvelteKit provided Builder object | | artifactPath | string | "build" | The path where to place to SvelteKit files | | esbuildOptions | any | | Options to pass to esbuild | | streaming | boolean | false | Use Lambda response streaming |

buildOptions(builder, artifactPath) ⇒ Promise.<string>

Kind: global function
Returns: Promise.<string> - Location of files for the options handler

| Param | Type | Default | Description | | ------------ | ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------ | | builder | any | | The SvelteKit provided Builder object | | artifactPath | string | "build" | The path where to place to SvelteKit files |

buildRouter(builder, static_directory, prerendered_directory, serverURL, optionsURL, artifactPath) ⇒ Promise.<string>

Kind: global function
Returns: Promise.<string> - Location of files for the origin router

| Param | Type | Default | Description | | --------------------- | ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------ | | builder | any | | The SvelteKit provided Builder object | | static_directory | string | | location of static page files | | prerendered_directory | string | | location of prerendered page files | | serverURL | string | | function URL for the server lambda | | optionsURL | string | | function URL for the options handler lambda | | artifactPath | string | "build" | The path where to place to SvelteKit files |

SiteProps : Object

Kind: global typedef
Properties

| Name | Type | Description | | --------------------- | ------------------- | ------------------------------------------- | | server_directory | string | location of files for the SSR server | | static_directory | string | location of static page files | | prerendered_directory | string | location of prerendered page files |

The functions above should be used within a SvelteKit adapter function; for example:

import {
  buildServer,
  buildOptions,
  buildRouter,
} from 'sveltekit-adapter-aws-base'

export default function ({
  artifactPath = 'build',
  esbuildOptions = {},
  // More options
} = {}) {
  /** @type {import('@sveltejs/kit').Adapter} */
  const adapter = {
    name: 'adapter-aws-myiacprovider',
    async adapt(builder) {
      const { serverDirectory, staticDirectory, prerenderedDirectory } =
        await buildServer(builder, artifactPath, esbuildOptions)
      const optionsDirectory = await buildOptions(builder, artifactPath)

      // Deploy server to lambda and get domain name of URL. These can use
      // AWS_IAM AuthType, as the router will sign requests.
      const serverDomain = getLambdaURLDomain(server_directory)
      const optionsDomain = getLambdaURLDomain(server_directory)

      const edgeDirectory = await buildRouter(
        builder,
        staticDirectory,
        prerenderedDirectory,
        serverDomain,
        optionsDomain,
        artifactPath
      )

      // Deploy router to lambda and get its arn
      const routerArn = getLambdaArn(edgeDirectory)

      // Upload static files to S3
      const myBucket = deployS3(staticDirectory, prerenderedDirectory)

      // Deploy a CloudFront CDN with the S3 bucket as the default origin
      // (with OAC for added security) and the lambda@edge function to handle
      // origin-requests.
      const CDN = deployCDN({
        defaultOriginBucket: myBucket,
        defaultCacheBehaviourOriginRequestHandler: routerArn,
      })
    },
  }

  return adapter
}

Example IAC providers

Credits

This package is derived from Mike Bild's adapter for CDK and James Bray's adapter for Serverless Framework.