-
Notifications
You must be signed in to change notification settings - Fork 31
feat: aws-lambda adapter
#104
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
Open
OskarLebuda
wants to merge
8
commits into
main
Choose a base branch
from
feat/aws-lambda
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ef2120
feat: add aws-lambda adapter
OskarLebuda e858256
chore: remove `--experimental-strip-types` in scripts (#105)
iiio2 82817a7
types: declare optional `ServerRequest.context`
pi0 5c582ad
chore(release): v0.8.7
pi0 fe3d202
chore: update deps
OskarLebuda 28806c0
chore: fix typo (#106)
Speelwolf b9db5dd
Merge branch 'main' into feat/aws-lambda
OskarLebuda df0a86b
feat: add aws-lambda adapter
OskarLebuda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,29 @@ | ||
| --- | ||
| icon: clarity:cloud-traffic-line | ||
| --- | ||
|
|
||
| # Serverless | ||
|
|
||
| > Deploy to any serverless platform | ||
|
|
||
| `srvx` provides built-in support for serverless platforms, allowing you to deploy your applications to various serverless environments without changing your code. | ||
|
|
||
| ### AWS Lambda | ||
|
|
||
| `srvx` includes an AWS Lambda adapter that enables you to run your applications on AWS Lambda. The adapter handles all the necessary transformations between AWS Lambda's event format and standard web Request/Response objects, making it seamless to run your application in a serverless environment. | ||
|
|
||
| To AWS Lambda adapter, you can use the `toLambdaHandler` function from the AWS Lambda adapter: | ||
|
|
||
| ```ts | ||
| import { toLambdaHandler } from "srvx/aws-lambda"; | ||
|
|
||
| export const handler = toLambdaHandler({ | ||
| fetch(req: Request) { | ||
| return Response.json({ hello: "world!" }); | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| The `toLambdaHandler` function accepts a `ServerOptions` object as its parameter (see [Server Options](/guide/options) for details). However, since this is a serverless environment, options related to the server instance like `host` and `port` are not respected and will be ignored. | ||
|
|
||
| You can find a complete example of AWS Lambda in the [examples/aws-lambda](https://github.com/h3js/srvx/tree/main/examples/aws-lambda) directory, which includes configuration for the Serverless Framework and demonstrates how to set up API Gateway endpoints. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 @@ | ||
| { | ||
| "name": "srvx-examples-aws-lambda", | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "start": "serverless offline --stage local --noPrependStageInUrl --host 0.0.0.0", | ||
| "dev": "srvx" | ||
| }, | ||
| "devDependencies": { | ||
| "srvx": "latest", | ||
| "serverless": "^3", | ||
| "serverless-offline": "^14.4.0" | ||
| } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| import { toLambdaHandler } from "srvx/aws-lambda"; | ||
|
|
||
| export const handler = toLambdaHandler({ | ||
| fetch(req: Request) { | ||
| return Response.json({ hello: "world!" }); | ||
| }, | ||
| }); |
This file contains hidden or 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,35 @@ | ||
| service: srvx-examples-aws-lambda | ||
| frameworkVersion: "3" | ||
|
|
||
| provider: | ||
| name: aws | ||
| runtime: nodejs20.x | ||
| region: eu-central-1 | ||
| stage: local | ||
|
|
||
| plugins: | ||
| - serverless-offline | ||
|
|
||
| package: | ||
| patterns: | ||
| - dist/** | ||
|
|
||
| functions: | ||
| api: | ||
| handler: server.handler | ||
| events: | ||
| - http: | ||
| path: / | ||
| method: ANY | ||
| cors: true | ||
| - http: | ||
| path: /{proxy+} | ||
| method: ANY | ||
| cors: true | ||
|
|
||
| custom: | ||
| serverless-offline: | ||
| noPrependStageInUrl: true | ||
| httpPort: 3000 | ||
| lambdaPort: 3001 | ||
| host: 0.0.0.0 |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.