Description
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