Why would we want to host a .NET Core Web Application inside a single Lambda function?

Viewed 324

I've been reading up on Amazon Lambda and experimenting on creating web APIs to be used. My understanding is that with the creation of each function, we can create a resource to point to the function and each function would be independent of any other functions. Should we want to use shared libraries, we can do that in the function itself or have the API gateway call an intermediary function which then proxies off the proper request to a final function to create a response.

With the addition of a web API solution that can be hosted on AWS Lambda, why would we ever want to host a complete web app on lambda when an EC2 instance would give more control if we are just going to deploy the whole application?

2 Answers

I use Lambda for one of my .NET Core Web API projects, seems ok so far. The main benefits are:

  • Very easy to deploy to different environments/stages
  • Don't have to worry about servers and load balancers
  • Could be more cost effective if the application isn't used that much (i.e. no need to run servers 24/7) This is also true if you have a cache sitting in front of it (you'll probably be using the API Gateway Cache)

The only negative thing I can think of at the moment is the Startup time of ASPNET. Hitting a cold endpoint can easily take ~5 seconds, maybe quite a bit more if it's pulling in a lot of assemblies and you're running on a small Lambda (i.e. 256MB)

For small projects (usually volunteer projects for kids schools), I can normally stay within the free tier, especially if I am using DynamoDB as by data store. For work which has higher performance requirements, I deploy them to an auto-scaling group of EC2s.

What I really like about using the AWS templates for "ASP.Net Core Web API" is that I can develop them as a console app and later build and deploy them to either EC2 or as a serverless Lambda project (or sometimes both).

For simplicity, I do build all of my Web API functions into a single app. This would be the norm when deploying to EC2. There are some negatives when deploying as a Lambda because not all functions require the same about of resources, so you have to provision the Lambda with the max required resources even if most of the calls would run just fine with minimal resources. To be more efficient with Lambdas, would might break them up into several projects to deployed to lambdas of different sizes (small, medium, large) but then I have to maintain 3 projects instead of one.

Hope this helps

Related