Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy aws / add streaming #910

Merged
merged 9 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ npm run build -- --with-aws-lambda
```

The handler entrypoint is `dist/serve-asw-lambda.js`: see [Hono AWS Lambda Deploy Docs](https://hono.dev/getting-started/aws-lambda#_3-deploy).
Streaming can be activated by setting environment variable `DEPLOY_AWS_LAMBDA_STREAMING=true npm run build -- --with-aws-lambda`

## Community

Expand Down
66 changes: 64 additions & 2 deletions docs/builder/aws-lambda.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The entry handler for the Lambda is `dist/serve-aws-lambda.handler`.

> Folder which require directly access - eg. `fs.readFile("./private/data.json")` needs to be manual added to the deployment configuration.

> **activate Streaming support:** `DEPLOY_AWS_LAMBDA_STREAMING=true pnpm build --with-aws-lambda`

## [Serverless Framework](https://www.serverless.com)

### Installation
Expand Down Expand Up @@ -67,7 +69,7 @@ This configuration will include all files from the `./private` directory in the
### Deploy

```sh
pnpm dlx serverless deploy
pnpx serverless deploy
```

Output:
Expand All @@ -92,7 +94,7 @@ Initialize your project with the `cdk` CLI

```sh
mkdir cdk && cd "$_"
pnpm dlx cdk init app -l typescript --generate-only
pnpx cdk init app -l typescript --generate-only
cd ..
cp cdk/cdk.json .
```
Expand Down Expand Up @@ -242,3 +244,63 @@ pnpm cdk deploy WakuStack
```

For more configuration options and how to use a custom domain visit the AWS CDK [documentation](https://docs.aws.amazon.com/cdk/v2/guide/home.html)

## sst.dev V3

This example requires a build with activated streaming.
`DEPLOY_AWS_LAMBDA_STREAMING=true pnpm build --with-aws-lambda`

### Setup

1. add `pnpm sst@latest init`

### configuration

use this as an example to run WAKU as Lamda Function:

sst.config.ts

```ts
/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
app(input) {
return {
name: 'waku03demo',
removal: input?.stage === 'production' ? 'retain' : 'remove',
home: 'aws',
};
},
async run() {
const WakuDemoApp = new sst.aws.Function('WakuDemoApp', {
url: true,
streaming: true,
//timeout: "15 minutes",
handler: 'dist/serve-aws-lambda.handler',
bundle: 'bundle', // disable bundling with esbuild
copyFiles: [
{
from: 'dist',
},
{
from: 'private',
},
],
environment: {
NODE_ENV: 'production',
},
});
return {
api: WakuDemoApp.url,
};
},
});
```

### deploy

```sh
pnpx sst deploy
```

[sst.dev documentation](https://sst.dev/docs)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DIST_PUBLIC } from '../builder/constants.js';

const SERVE_JS = 'serve-aws-lambda.js';

const lambdaStreaming = process.env.DEPLOY_AWS_LAMBDA_STREAMING === 'true';

const getServeJsContent = (
distDir: string,
distPublic: string,
Expand All @@ -19,7 +21,7 @@ import { runner, importHono, importHonoNodeServerServeStatic, importHonoAwsLambd

const { Hono } = await importHono();
const { serveStatic } = await importHonoNodeServerServeStatic();
const { handle } = await importHonoAwsLambda();
const { ${lambdaStreaming ? 'streamHandle:' : ''}handle } = await importHonoAwsLambda();
let contextStorage;
try {
({ contextStorage } = await import('hono/context-storage'));
Expand Down
Loading