Skip to content

Support API Gateway websocket api via LambdaServer#1804

Merged
GarrettBeatty merged 37 commits into
aws:devfrom
wiowou:websocket
May 15, 2026
Merged

Support API Gateway websocket api via LambdaServer#1804
GarrettBeatty merged 37 commits into
aws:devfrom
wiowou:websocket

Conversation

@wiowou
Copy link
Copy Markdown
Contributor

@wiowou wiowou commented Sep 5, 2024

Issue #, if available:

Description of changes:
Added a websocket option to the Amazon.Lambda.AspNetCoreServer project so that API Gateway websocket api's can also use the LambdaServer (DI, controllers, etc) given the user does the following:

  1. References the same lambda to handle the RouteKeys in API Gateway for which they have controller routes set up.
  2. Sets up controller routes as POST with path=RouteKey

Unit tests are passing.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@bhoradc
Copy link
Copy Markdown

bhoradc commented Sep 27, 2024

Hi @wiowou,

Thank you for contributing the PR. Our team will review it and get back to you as soon we can.

Regards,
Chaitanya

@wiowou
Copy link
Copy Markdown
Contributor Author

wiowou commented Sep 30, 2024

Thank you, @bhoradc !

-Behram

philasmar and others added 25 commits December 15, 2025 13:41
* 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)
@GarrettBeatty GarrettBeatty requested a review from Copilot May 12, 2026 18:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 typed TStartup variant) to translate WebSocket events into ASP.NET Core requests (POST + path from RouteKey).
  • Refactors APIGatewayProxyFunction to 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.

@wiowou wiowou requested review from a team as code owners May 13, 2026 00:54
@GarrettBeatty
Copy link
Copy Markdown
Contributor

GarrettBeatty commented May 14, 2026

hi thanks for the pr. can you rebase it on top of dev branch and change the target branch to dev please?

@wiowou
Copy link
Copy Markdown
Contributor Author

wiowou commented May 15, 2026

hi @GarrettBeatty - rebased to dev. It's been over a year since I've looked at this code and the tests for the websocket api are fairly simple. I don't know that I can do a real test of this anytime soon (as I did back then), since much of my setup and access has changed significantly. FYI, I'm piggy-backing off the APIGatewayHttpApiV2ProxyRequest and APIGatewayHttpApiV2ProxyResponse events.

@GarrettBeatty GarrettBeatty changed the base branch from master to dev May 15, 2026 00:55
@GarrettBeatty GarrettBeatty changed the base branch from dev to master May 15, 2026 00:55
@GarrettBeatty GarrettBeatty changed the base branch from master to dev May 15, 2026 00:57
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).
@GarrettBeatty
Copy link
Copy Markdown
Contributor

i cleaned up the pr and made some small adjustments (i think there was a bug). 26b9cd0

Comment thread Libraries/test/TestWebApp/Controllers/RouteKeyController.cs Dismissed
Records the public-API addition of APIGatewayWebsocketApiProxyFunction +
LambdaEventSource.WebsocketApi as a Minor bump on Amazon.Lambda.AspNetCoreServer
and Amazon.Lambda.AspNetCoreServer.Hosting.
@GarrettBeatty
Copy link
Copy Markdown
Contributor

@GarrettBeatty
Copy link
Copy Markdown
Contributor

i deployed some test function and connected via websocket and confirmed i see stuff in the logs


  WS-ROUTE route=$connect    connId=dYiMndS4oAMCIjg=
  WS-ROUTE route=$default    connId=dYiMndS4oAMCIjg= body={"action":"$default","msg":"hello from smoke test"}

so it seems to work

protected override HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider)
{
var handler = new APIGatewayWebsocketMinimalApi(serviceProvider);
#pragma warning disable CA2252
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@GarrettBeatty GarrettBeatty merged commit 44ba589 into aws:dev May 15, 2026
4 of 6 checks passed
@wiowou
Copy link
Copy Markdown
Contributor Author

wiowou commented May 16, 2026

@GarrettBeatty Thank you so much! I see the correct events were actually APIGatewayProxyRequest/Response ...was that the bug (dropping attributes) or was there more?

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.

7 participants