Skip to content
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

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

Open
2 tasks
Simonl9l opened this issue Jul 7, 2023 · 1 comment
Labels
annotations feature-request A feature should be added or improved. p2 This is a standard priority issue queued

Comments

@Simonl9l
Copy link

Simonl9l commented Jul 7, 2023

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

@Simonl9l Simonl9l added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 7, 2023
@ashishdhingra
Copy link
Contributor

Needs review with the team.

@ashishdhingra ashishdhingra added needs-review annotations and removed needs-triage This issue or PR still needs to be triaged. module/lambda-client-lib labels Jul 10, 2023
@ashishdhingra ashishdhingra added p2 This is a standard priority issue and removed needs-review labels Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations feature-request A feature should be added or improved. p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

2 participants