Serverless doesn't mean giving up full-featured APIs. With AWS Lambda and API Gateway, you can run .NET Web APIs in a fully managed, scalable way without provisioning servers. In this post, we'll walk through deploying a minimal .NET API to AWS Lambda using API Gateway as the front door. Prerequisites .NET 6 or later SDK
AWS CLI (configured with credentials)
Amazon.Lambda.Tools CLI Install the AWS Lambda tools globally if you haven’t already: dotnet tool install -g Amazon.Lambda.Tools Step 1: Create a Minimal API We'll start with a simple .NET 6+ Web API using Minimal APIs: dotnet new webapi -n MyLambdaApi cd MyLambdaApi (Optional) Clean up the template a bit and define your own minimal endpoint in Program.cs: var app = WebApplication.Create(args); app.MapGet("/hello", () => "Hello from Lambda!"); app.Run(); Step 2: Add Lambda Support Install The Necessary NuGet Packages dotnet add package Amazon.Lambda.AspNetCoreServer dotnet add package Amazon.Lambda.RuntimeSupport Then, Add a New Class LambdaEntryPoint.cs public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction { protected override void Init(IWebHostBuilder builder) { builder.UseStartup(); } } Make sure Startup.cs exists and configures your services like normal. Step 3: Add Lambda Project Configuration Create a Aws-lambda-tools-defaults.json File In The Project Root { "profile": "default", "region": "us-east-1", "configuration":
"Release", "framework": "net6.0", "function-runtime": "dotnet6", "function-handler": "MyLambdaApi::MyLambdaApi.LambdaEntryPoint::FunctionHandlerAsync", "function-memory-size": 512, "function-timeout": 30, "function-name": "MyLambdaApi", "function-role": "arn:aws:iam::123456789012:role/your-lambda-role" } Step 4: Deploy to AWS Lambda Build And Deploy Using The Lambda Tools dotnet lambda deploy-serverless This command packages your app, creates a Lambda function, and wires it to an API Gateway endpoint.
After
Deployment, It Will Print a URL Like https://xyz123.execute-api.us-east-1.amazonaws.com/Prod/hello You can test it using curl or a browser. Step 5: Test the Endpoint curl https://xyz123.execute-api.us-east-1.amazonaws.com/Prod/hello # → Hello from Lambda!
Cleanup To Avoid
Charges aws cloudformation delete-stack --stack-name MyLambdaApi Summary You’ve just deployed a real .NET Web API to AWS Lambda using API Gateway with no servers in sight. This pattern is perfect for lightweight APIs, backend services, and microservices. Stay tuned for the next post in the CloudSharp series, where we'll wire this API to a DynamoDB backend. References AWS Lambda for .NET
Amazon.Lambda.Tools GitHub Repo
Deploying .NET Lambda Functions
ASP.NET Core Minimal APIs
API Gateway and Lambda Integration
📌 Deploying .NET APIs to AWS Lambda with API Gateway (Jun)
🏢 Renato Gonçalves
📍 Jun
Postulate a este anuncio
Muestra tus habilidades a la empresa, rellenar el formulario y deja un toque personal en la carta, ayudará el reclutador en la elección del candidato.