I have a .Net 6 API which is deployed on AWS lambda. In theory everything is set up right, but when I try to call the API from postman, it giver "internal server error".
The problem is a NullReferenceException.
2022-12-23T19:59:07.791Z 9b343352-fd3f-4c34-a1a5-3f46251b7f1e 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.AbstractAspNetCoreFunction`2.FunctionHandlerAsync(TREQUEST request, ILambdaContext lambdaContext)
at lambda_method2(Closure , Stream , ILambdaContext , Stream )
at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145
at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 56
at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176
I call the FunctionHandlerAsync in AWS, which I read is the correct function, I followed many tutorials on how to set it up, but even if I did it in the same way, just doesn't work.
Lambda entrypoint:
namespace API
{
public class LambdaFunction : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
try
{
builder.UseContentRoot(Directory.GetCurrentDirectory()).UseStartup<Startup>().UseLambdaServer();
}
catch (Exception ex)
{
throw ex;
}
}
}
}
Although the request passes, I also get some error when I try to test the API in the lambda test with
{
"statusCode": 404,
"headers": {},
"multiValueHeaders": {
"Content-Type": [
null
]
},
"body": "",
"isBase64Encoded": false
I am new to this cloud world and I would really need some solution to this, I am working on it for 3 days and literally the deployment generates me a way bigger headache than the actual creation of the API.