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

Conversation

aheissenberger
Copy link
Contributor

@aheissenberger aheissenberger commented Sep 27, 2024

adds streaming by using streamHandle from Hono.

To switch the handler use the environment variable DEPLOY_AWS_LAMBDA_STREAMING=true:

DEPLOY_AWS_LAMBDA_STREAMING=true pnpm build --with-aws-lambda

Copy link

vercel bot commented Sep 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Sep 28, 2024 0:30am

@aheissenberger aheissenberger marked this pull request as draft September 27, 2024 11:08
Copy link

codesandbox-ci bot commented Sep 27, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@aheissenberger
Copy link
Contributor Author

aheissenberger commented Sep 27, 2024

@rmarscher please help - it returns the wrong result in my tests with a function url and sst (fixed)

sst.config.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,
    };
  },
});

The result is this - what suggests that the return is not a stream from WAKU: (fixed)

{"body":"<!DOCTYPE html>
<html>
<head>
..
","headers":{"content-type":"text/html; charset=utf-8"},"statusCode":200,"isBase64Encoded":false}

~

@aheissenberger
Copy link
Contributor Author

@rmarscher it works now

please provide some input why you need to rearrange the dist folder. The sst setup above is only the shortest version to test streaming, other setups should not be a problem.

@rmarscher
Copy link
Contributor

Very cool. Thanks for giving SST a try. I rearrange the files to move unnecessary public files out of the function bundle - to reduce the lambda package size.

@rmarscher
Copy link
Contributor

Here is a demo I made for how I use SST with waku with an older patch of v0.21.1 - https://github.com/rmarscher/waku-sst-demo
It uses some core functions they have in a "SsrSite" module that all of their official meta framework components import. I need to update that too. Both SST and waku are moving pretty fast right now. SST's TanstackStart component is pretty similar for reference https://github.com/sst/ion/blob/dev/platform/src/components/aws/tanstack-start.ts.

@aheissenberger
Copy link
Contributor Author

@rmarscher in the serverless framework I only copy the needed folders to the lambda and all static files go to an s3 bucket. In Cloudfront I use behaviors to handle the forwarding of static requests and the default request are handled by the lambda function. I know this is not as fancy as using a Cloudfunction to route all static assets but deployments in non US East (N. Virginia) get quit complex if you need to deploy on project to multiple regions as the Cloundfunction have to be deployed to US East (N. Virginia). Yes, this is much simpler with sst ;-)

It should be possible keep the current file structure with the sst framework. Looking at TanstackStart Stack I suggest that @dai-shi asks directly asks for support in creating the stack. Tanstack sst stack was created by Frank Wang the founder of sst.

@rmarscher if you agree, I would finish this PR as creating an sst stack should be in its own PR.

@dai-shi
Copy link
Owner

dai-shi commented Sep 27, 2024

Looking at TanstackStart Stack I suggest that @dai-shi asks directly asks for support in creating the stack.

What should I do? Open an issue?

@aheissenberger
Copy link
Contributor Author

Looking at TanstackStart Stack I suggest that @dai-shi asks directly asks for support in creating the stack.

What should I do? Open an issue?

yes, and maybe ping Frank to have a look at WAKU as one of the best alternatives to Next.js

@aheissenberger aheissenberger marked this pull request as ready for review September 27, 2024 21:48
@dai-shi
Copy link
Owner

dai-shi commented Sep 27, 2024

sst/ion#1159

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good other than that. needs to run prettier?

@aheissenberger
Copy link
Contributor Author

looks good other than that. needs to run prettier?

Done

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dai-shi dai-shi merged commit 18a827b into dai-shi:main Sep 28, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants