Lightweight version on Minimal API in Annotations - Single Handler for multiple Requests
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-lambda-dotnet
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
aws/aws-lambda-dotnet#2571 · 1 comment ·
-
bug module/aspnetcore-support p2 queued
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
aws/aws-lambda-dotnet#1123 · 4 comments · 1 reaction ·
-
feature-request
Difficulty 4/5 3-5 days Newbie friendliness 68/100
aws/aws-lambda-dotnet#2572 · 1 comment ·
-
feature-request needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
aws/aws-lambda-dotnet#2551 · 1 comment ·
-
feature-request needs-review
Difficulty 5/5 Over a week Newbie friendliness 35/100
aws/aws-lambda-dotnet#2519 ·
All issues in aws/aws-lambda-dotnet
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·