Skip to main content

Command Palette

Search for a command to run...

Deploying .NET APIs to AWS Lambda with API Gateway

Updated
2 min read
Deploying .NET APIs to AWS Lambda with API Gateway
R

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.

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

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

CloudSharp

Part 3 of 4

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.

Up next

Running .NET on AWS Lambda: A Quick Start Guide

Amazon Web Services (AWS) Lambda is a serverless compute service that lets you run code without provisioning or managing servers. With support for .NET, you can build Lambda functions in C# and deploy them seamlessly. In this guide, you'll learn how ...

More from this blog

C

Code With Renato

15 posts