Support API Gateway websocket api via LambdaServer#1804
Conversation
|
Hi @wiowou, Thank you for contributing the PR. Our team will review it and get back to you as soon we can. Regards, |
|
Thank you, @bhoradc ! -Behram |
Sync dev and main
* doc: update readme to point at changelog correctly (aws#2243) * Bump tj-actions/changed-files from 47.0.0 to 47.0.1 (aws#2239) Bumps [tj-actions/changed-files](https://github.com/tj-actions/changed-files) from 47.0.0 to 47.0.1. - [Release notes](https://github.com/tj-actions/changed-files/releases) - [Changelog](https://github.com/tj-actions/changed-files/blob/main/HISTORY.md) - [Commits](tj-actions/changed-files@24d32ff...e002140) --- updated-dependencies: - dependency-name: tj-actions/changed-files dependency-version: 47.0.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump aws-actions/configure-aws-credentials from 5.0.0 to 5.1.1 (aws#2238) Bumps [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) from 5.0.0 to 5.1.1. - [Release notes](https://github.com/aws-actions/configure-aws-credentials/releases) - [Changelog](https://github.com/aws-actions/configure-aws-credentials/blob/main/CHANGELOG.md) - [Commits](aws-actions/configure-aws-credentials@a03048d...61815dc) --- updated-dependencies: - dependency-name: aws-actions/configure-aws-credentials dependency-version: 5.1.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add grouping for GitHub Actions updates (aws#2247) Group all GitHub Actions updates into a single PR. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Samuel <sam.r.c@hotmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
chore: Daily ASP.NET Core version update in Dockerfiles
Update Lambda Runtime Images for NET 11 (aws#2302)
Merge dev to master
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for API Gateway WebSocket API events to be processed through Amazon.Lambda.AspNetCoreServer so WebSocket RouteKeys can be routed into ASP.NET Core controllers / DI via LambdaServer.
Changes:
- Introduces
APIGatewayWebsocketApiProxyFunction(and typedTStartupvariant) to translate WebSocket events into ASP.NET Core requests (POST + path fromRouteKey). - Refactors
APIGatewayProxyFunctionto allow overriding HTTP path/method/header derivation and adds ConnectionId propagation. - Adds a test web app controller + request fixture + unit test validating routing/serialization behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Libraries/test/TestWebApp/WebsocketApiLambdaFunction.cs | Adds a test Lambda entrypoint using the new WebSocket proxy base class. |
| Libraries/test/TestWebApp/Controllers/RouteKeyController.cs | Adds a controller route simulating API Gateway RouteKey routing via POST. |
| Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/values-post-withbody-websocketapi-request.json | Adds a sample WebSocket event payload fixture for tests. |
| Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/TestApiGatewayWebsocketApiCalls.cs | Adds a unit test invoking the WebSocket proxy function end-to-end. |
| Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/Amazon.Lambda.AspNetCoreServer.Test.sln | Adds a solution file for the test project. |
| Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayWebsocketApiProxyFunction{TStartup}.cs | Adds the typed Startup variant for WebSocket proxy functions. |
| Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayWebsocketApiProxyFunction.cs | Adds the WebSocket proxy implementation (path/method/headers). |
| Libraries/src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs | Refactors request marshalling to use overridable parsing hooks; propagates ConnectionId. |
| Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/ServiceCollectionExtensions.cs | Adds new LambdaEventSource.WebsocketApi wiring to runtime server selection. |
| Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/Internal/LambdaRuntimeSupportServer.cs | Adds runtime support server for WebSocket API Minimal API hosting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
hi thanks for the pr. can you rebase it on top of |
|
hi @GarrettBeatty - rebased to |
The websocket runtime-support server was wired to the v2 APIGatewayHttpApiV2ProxyFunction handler with v2 request/response types, so AddAWSLambdaHosting(LambdaEventSource.WebsocketApi) never ran the websocket-specific path/method/header overrides and dropped fields like ConnectionId. Switch it to the v1 APIGatewayWebsocketApiProxyFunction flow and have the websocket MinimalApi inherit from the REST one, overriding only the three websocket virtuals. Tighten doc comments on the new types and on ParseHttpPath/ParseHttpMethod/AddMissingRequestHeaders, and remove the stray test .sln (the project builds via the existing .csproj from Libraries.sln).
|
i cleaned up the pr and made some small adjustments (i think there was a bug). 26b9cd0 |
Records the public-API addition of APIGatewayWebsocketApiProxyFunction + LambdaEventSource.WebsocketApi as a Minor bump on Amazon.Lambda.AspNetCoreServer and Amazon.Lambda.AspNetCoreServer.Hosting.
|
i deployed some test function and connected via websocket and confirmed i see stuff in the logs so it seems to work |
| protected override HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider) | ||
| { | ||
| var handler = new APIGatewayWebsocketMinimalApi(serviceProvider); | ||
| #pragma warning disable CA2252 |
There was a problem hiding this comment.
46dc956#diff-dec0ad4ae2f92f72fd5cabb763659b9a222002446a2e7fb9c77120d231c18d88R363 from the response streaming pr
|
@GarrettBeatty Thank you so much! I see the correct events were actually |
Issue #, if available:
Description of changes:
Added a
websocketoption to theAmazon.Lambda.AspNetCoreServerproject so that API Gateway websocket api's can also use theLambdaServer(DI, controllers, etc) given the user does the following:RouteKeys in API Gateway for which they have controller routes set up.POSTwith path=RouteKeyUnit tests are passing.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.