Search code examples
asp.net-coreaws-lambdaserilogamazon-cloudwatchlogs

Serilog to CloudLog does not work from lambda


I'm stuck with the following issue. I host a 'hello world' ASP.NET Core Web API application in lambda and want to log some application-specific information for Cloud Watch. I use https://github.com/aws/aws-logging-dotnet with a serilog as a logger. I followed all the instructions.

Lambda has needed permissions: lambda

appsetting.json file: app settings

Startup: startup

Controller: startup

Deployed, try to call action: get 502 error.

Go to Cloudlogs:

log group is not created(should be as the region is the same)

6.2 Lambda's logs are: lambda So I guess Webapp fails during configuration, and that's it. Could someone give me a hint about what's wrong? I tried a dozen of different approaches - no chance. Once I remove the logging configuration from the startup - everything works.


Solution

  • Increase your lambda timeout , you lambda is timing out after 3 seconds because yoru application is not responding withing that time. As we can see in the log that your application has started but before before completeing its timing out. Increaing the timeout for lambda will solve your issue as its taking longer than 3 seconds to initialize your app and start logging. .NET core runtime has cold start when using in lambda.

    But you too need to consider decreasing the application startup time by optimizing the serilog configuration and avoinding external depndencies.