This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
# sst | ||
.sst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Hono } from "hono"; | ||
import { streamText } from "hono/streaming"; | ||
import { handle, streamHandle } from "hono/aws-lambda"; | ||
|
||
const app = new Hono() | ||
.get("/", (c) => { | ||
return streamText(c, async (stream) => { | ||
await stream.writeln("Hello"); | ||
await stream.sleep(3000); | ||
await stream.writeln("World"); | ||
}) | ||
}); | ||
|
||
export const handler = process.env.SST_LIVE ? handle(app) : streamHandle(app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "aws-hono-stream", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"hono": "^4.6.2", | ||
"sst": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* This file is auto-generated by SST. Do not edit. */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import "sst" | ||
export {} | ||
declare module "sst" { | ||
export interface Resource { | ||
"Hono": { | ||
"name": string | ||
"type": "sst.aws.Function" | ||
"url": string | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// <reference path="./.sst/platform/config.d.ts" /> | ||
|
||
/** | ||
* ## AWS Hono streaming | ||
* | ||
* An example on how to enable streaming for Lambda functions using Hono. | ||
* | ||
* ```ts title="sst.config.ts" | ||
* { | ||
* streaming: true | ||
* } | ||
* ``` | ||
* | ||
* While `sst dev` doesn't support streaming, we can conditionally enable it on deploy. | ||
* | ||
* ```ts title="index.ts" | ||
* export const handler = process.env.SST_LIVE ? handle(app) : streamHandle(app); | ||
* ``` | ||
* | ||
* This will return the standard handler for `sst dev`. | ||
* | ||
* :::note | ||
* Streaming is currently not supported in `sst dev`. | ||
* ::: | ||
* | ||
* To test this in your terminal, use the `curl` command with the `--no-buffer` option. | ||
* | ||
* ```bash "--no-buffer" | ||
* curl --no-buffer https://u3dyblk457ghskwbmzrbylpxoi0ayrbb.lambda-url.us-east-1.on.aws | ||
* ``` | ||
* | ||
* Here we are using a Function URL directly because API Gateway doesn't support streaming. | ||
* | ||
*/ | ||
export default $config({ | ||
app(input) { | ||
return { | ||
name: "aws-hono-stream", | ||
home: "aws", | ||
removal: input?.stage === "production" ? "retain" : "remove", | ||
}; | ||
}, | ||
async run() { | ||
const hono = new sst.aws.Function("Hono", { | ||
url: true, | ||
streaming: true, | ||
timeout: "15 minutes", | ||
handler: "index.handler", | ||
}); | ||
return { | ||
api: hono.url, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |