
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
AWS CLI (configured with credentials)
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<Startup>();
}
}
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
About the author
With over 14 years in software development, I specialize in backend systems using .NET, Python, and Java. I bring full lifecycle expertise, including requirements analysis, client/server and data layer development, automated testing (unit, integration, end-to-end), and CI/CD implementations using Docker, GitLab Pipelines, GitHub Actions, Terraform, and AWS CodeStar.
Comments
Join the discussionNo comments yet. Be the first to comment.
CloudSharp
CloudSharp: .NET on AWS is a practical blog series that guides developers in building, deploying, and scaling .NET apps with AWS. From Lambda to S3 and serverless APIs, learn how to bring your .NET code to the cloud with clarity and confidence.




