como estan? Estoy intentando hacer un Deploy a AWS Lambda de mi proyecto de API, me hace el deploy correctamente pero al tratar de consumir una API mediante la URL que me da AWS me arroja el siguiente error:
{"message": "Internal server error"}
Les dejo mi codigo de configuracion:
serverless.template:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Transform" : "AWS::Serverless-2016-10-31",
"Description" : "Starting template for an AWS Serverless Application.",
"Parameters" : {
},
"Resources" : {
"DefaultFunction" : {
"Type" : "AWS::Serverless::Function",
"Properties": {
"Handler": "RtvcApi::RtvcApi.LambdaEntryPoint::FunctionHandlerAsync",
"Runtime": "dotnet6",
"CodeUri": "",
"Description": "Default function",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [ "AWSLambda_FullAccess" ],
"Events": {
"ProxyResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
}
}
}
}
},
"Outputs" : {
"ApiURL" : {
"Description" : "API endpoint URL for Prod environment",
"Value" : { "Fn::Sub" : "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/" }
}
}
}
aws-lambda-tools-defaults.json
{
"Information" : [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile" : "StoreSysAWS",
"region" : "us-east-1",
"configuration" : "Release",
"function-runtime" : "dotnet6",
"framework" : "net6.0",
"template" : "serverless.template",
"template-parameters" : "",
"s3-prefix" : "CoreAPI/",
"s3-bucket" : "rtvapibucket",
"stack-name" : "CoreAPIStack"
}
LambdaEntryPoint.cs
using Amazon.Lambda.AspNetCoreServer;
namespace RtvcApi;
public class LambdaEntryPoint : APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Program>()
.UseLambdaServer();
}
}
Program.cs
using CleanArchitecture.Identity;
using Infrastructure.EntityFramework;
using RtvcApi;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Directory.GetCurrentDirectory());
var app = CreateHostBuilder(args).Build();
app.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
return Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
webBuilder =>
webBuilder
.UseStartup<Startup>())
.ConfigureServices((context, services) =>
{
services.AddControllers();
services.AddApplicationServices();
services.AddAuthentication();
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
);
});
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddInfrastructureServices(configuration);
services.ConfigureAuthenticationServices(configuration);
services.AddAuthorization();
});
}
}
Startup.cs
using RtvcApi.Middlewares;
namespace RtvcApi;
public class Startup
{
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors("CorsPolicy");
app.UseRouting();
app.UseMiddleware<ExceptionMiddleware>();
app.UseAuthorization();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapGet("/test", async context =>
{
await context.Response.WriteAsync("va...");
});
});
}
}
Intente de muchas formas para subir y publicar la API, en todas me las sube bien pero me tira siempre el mismo error.
Ejemplos de links en los que intente:
https://nodogmablog.bryanhogan.net/2022/10/simple-dependency-injection-for-net-lambda-functions/
https://github.com/aws/aws-lambda-dotnet/discussions/1370
https://nodogmablog.bryanhogan.net/2022/01/net-6-web-api-in-a-container-in-a-lambda/
https://aws.amazon.com/es/blogs/compute/introducing-the-net-6-runtime-for-aws-lambda/
Desde ya muchas gracias, espero puedan ayudarme ! Saludos
Configure
en la claseProgram
... tu lo tienes definido en la claseStartup
. Cambia el método de sitio (o no se si habrá alguna forma de indicar la ubicación real del método)