I publish my api project at aws lambda. After publishing, when i test API this error showing:
{
"errorType": "NullReferenceException",
"errorMessage": "Object reference not set to an instance of an object.",
"stackTrace": [
"at Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayHttpApiV2ProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)",
"at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction2.FunctionHandlerAsync(TREQUEST request, ILambdaContext lambdaContext)", "at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass26_0
2.<<GetHandlerWrapper>b__0>d.MoveNext()",
"--- End of stack trace from previous location ---",
"at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken)"
]
}
And when call any endpoint the response is:
can't parse JSON. Raw result:
Internal Server Error
This is program.cs file
using BT.API.Extensions;
using BT.API.Hubs;
using BT.Repository.Domains.Requests;
using Core.Constants;
using Core.Filters;
using Core.Infrastructure.Options;
using Core.Infrastructure.Security;
using Core.Interfaces.Services;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, configuration) =>
{
configuration.ReadFrom.Configuration(context.Configuration);
});
//builder.Services.AddCorsServices(builder.Configuration);
builder.Services.Configure<CorsOptions>(builder.Configuration.GetSection(nameof(CorsOptions)));
var corsOptions = builder.Configuration.GetSection(nameof(CorsOptions))
.Get(typeof(CorsOptions)) as CorsOptions;
builder.Services.AddCors(options =>
{
options.AddPolicy(corsOptions.PolicyName, policy =>
{
policy.AllowAnyHeader().AllowAnyMethod();
if (corsOptions != null)
{
policy.WithOrigins(corsOptions.Origins);
}
else
{
policy.AllowAnyOrigin();
}
policy.AllowCredentials().SetIsOriginAllowed((host) => true);
});
});
builder.Services.AddControllers(options =>
{
options.Filters.Add(typeof(InputValidationFilter));
// options.Filters.Add(typeof(ExceptionFilter));
})
.AddFluentValidation(fv =>
{
fv.RegisterValidatorsFromAssemblyContaining<SignInRequest>();
})
.AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
.AddFluentValidation(x => x.RegisterValidatorsFromAssemblyContaining<SignInRequest>());
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "BT.API", Version = "v1" });
c.AddSignalRSwaggerGen();
});
builder.Services.AddDependencies(builder.Configuration);
builder.Services.AddScoped<IAuthenticatedUser, AuthenticatedUser>();
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "BT.API v1");
});
}
var corsOptionss = builder.Configuration.GetSection(nameof(CorsOptions))
.Get(typeof(CorsOptions)) as CorsOptions;
app.UseCors(corsOptions.PolicyName);
app.UseDependencies(builder.Configuration, app.Services.GetRequiredService<ILoggerFactory>());
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Map("/api/hello", app =>
{
app.Run(async context =>
{
await context.Response.WriteAsync("Hello, world!");
});
});
app.MapHub<SocketHub>(Constants.SOCKET_HUB);
app.Run();