Lightweight version on Minimal API in Annotations - Single Handler for multiple Requests

Open
#1,544 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
aws, csharp
Domain
api, cloud

Research direction

Start by reading the Amazon.Lambda.Annotations implementation around [LambdaFunction] and the serverless.template generation mentioned in the issue. Establish how multiple annotated routes could share one handler while retaining parameter binding and response processing; done means the deployment maps those routes to a single Lambda handler.

Written by the indexing model from the issue text.

Description

annotations feature-request p2 queued
Describe the feature

Today the annotations project support multiple handlers, however this means the same lambda needs to be deployed multiple times, once for each handler.

Use Case

Whilst the Minimal API provides a single handler to serves multiple requests, in many cases this is overkill.

If no conventional middleware support is required (just a DI container), it would be great to add a level of indirection into Annotations such that it can meet the same use cases in a more compact footprint.

A suite of related API's can then scale up/out based on need than at the more granular hander level. This also simplifies the deployment model.

Proposed Solution

The indirection could be based on the raw APIGatewayProxyRequest/APIGatewayProxyResponse that can be achieved today. However this leads a lot for manual implementation than leverage the components that already exist in the library with the attributes [FromBody], [FromServices] etc.

 [LambdaFunction]
    public async Task<APIGatewayProxyResponse> FunctionHandlerAsync(
        APIGatewayProxyRequest request, 
        [FromServices] IServiceProvider provider, 
        [FromServices] ILogger<Functions> logger,
        ILambdaContext context)
    {
        // with a switch on the request path to an implementation and delegate to a sub handler. 
        // That in turn can deserialize the body, and
        // use the IServiceProvider to pull needed services. 
        // It would also have to deserialize the response
      
    }

Perhaps there is a new attribute called (say) [SubLambdaFunction] that behaves similarly to the current [LambdaFunction] that causes the underlying method above to be source generated that in runs invokes each [SubLambdaFunction] and handles the response processing?

Other Information

The serverless.template would still generate for the specific routes of each request as deployed to the API G/W mapping them to the same single Lambda Handler than one for each.

Acknowledgements
  • I may be able to implement this feature request
  • This feature might incur a breaking change
AWS .NET SDK and/or Package version used

Amazon.Lambda.Annotations

Targeted .NET Platform

.Net 6/7/8

Operating System and version

N/A

Dominant language
C#
Stars
1.7k
Forks
503
Avg merge
1d 18h
Merged PRs (30d)
21

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-lambda-dotnet

All issues in aws/aws-lambda-dotnet

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.