awslabs / aws-dotnet-messaging

An AWS-native framework that simplifies the development of .NET message processing applications that use AWS services, such as SQS, SNS, and EventBridge.
https://awslabs.github.io/aws-dotnet-messaging/
Apache License 2.0
63 stars 10 forks source link

ASPNET Minimal API on Lambda throws an error #140

Open GunboatDiplomat opened 3 weeks ago

GunboatDiplomat commented 3 weeks ago

Describe the bug

Can not use together with ASPNET Minimal API Lambda runtime

Expected Behavior

No error is thrown.

Current Behavior

This error is shown in logs: fail System.NullReferenceException: Object reference not set to an instance of an object. at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest, ILambdaContext lambdaContext) at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction2.FunctionHandlerAsync(TREQUEST request, ILambdaContext lambdaContext) at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass26_02.<<GetHandlerWrapper>b__0>d.MoveNext() --- End of stack trace from previous location --- at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken)

Reproduction Steps

Simple example:

var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi);
builder.Services.AddAWSMessageBus(b =>
{
    b.AddSQSPoller(...);
    b.AddMessageHandler<ExampleMessageHandler, ExampleMessage>();
    b.AddLambdaMessageProcessor();
});
var app = builder.Build()

How are we supposed to use ILambdaMessaging together with aspnet minimal api runtime?

Possible Solution

No response

Additional Information/Context

No response

AWS.Messaging (or related) package versions

AWS.Messaging (0.9.1)

Targeted .NET Platform

.NET8

Operating System and version

AmazonLinux

ashishdhingra commented 2 weeks ago

@GunboatDiplomat Good afternoon. I'm unsure if you are using the messaging library correctly. Ideally, the Poller should be used in applications with long running process (refer Consume messages with the AWS Message Processing Framework for .NET). AWS Messaging with Lambda ASP.NET scenario should ideally use Publisher API (refer PublisherAPI example).

CC @normj / @ashovlin for any inputs.

Thanks, Ashish