Running .NET on AWS Lambda: A Quick Start Guide

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.
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 to create, build, and deploy a .NET Lambda function using the AWS .NET tooling.
Prerequisites
Before you start, make sure you have:
AWS CLI (configured with credentials)
An AWS account
Install the Lambda tooling with:
dotnet tool install -g Amazon.Lambda.Tools
Step 1: Create a Lambda Project
You can create a new Lambda project using one of the AWS templates:
dotnet new lambda.EmptyFunction --name MyLambdaFunction
cd MyLambdaFunction
The main function logic will be in Function.cs, under the method FunctionHandler.
Step 2: Write Your Function Logic
Edit Function.cs to match your logic. For example:
public class Function
{
public string FunctionHandler(string input, ILambdaContext context)
{
return $"Hello, {input}!";
}
}
Step 3: Test Locally
You can test the function locally with:
dotnet lambda invoke-function MyLambdaFunction --payload "World"
Step 4: Deploy to AWS
Deploy using the Lambda tools:
dotnet lambda deploy-function MyLambdaFunction
You’ll be prompted for details like the IAM role, region, and function name. You can also use --function-role, --region, and other flags to script deployments.
Step 5: Invoke from AWS Console or API
Once deployed, you can:
Test it from the AWS Lambda Console
Invoke it using the AWS CLI:
aws lambda invoke \
--function-name MyLambdaFunction \
--payload "\"John Doe\"" \
output.json
Optional: Set Up API Gateway
To expose your Lambda via HTTP, connect it to API Gateway:
In the AWS Console, go to API Gateway.
Create a new HTTP API.
Add an integration with your Lambda.
Deploy the API and use the URL to invoke your Lambda.
Cleanup
To delete the Lambda and avoid charges:
aws lambda delete-function --function-name MyLambdaFunction
Conclusion
Running .NET on AWS Lambda is a great way to take advantage of serverless architecture while using C#. With a few CLI commands, you can deploy scalable functions to the cloud without managing infrastructure.
Need advanced patterns, like dependency injection, configuration, or async I/O? AWS .NET Lambda projects support all of them. Let me know if you want a follow-up post on those topics.
References
AWS Lambda for .NET
https://docs.aws.amazon.com/lambda/latest/dg/dotnet.htmlAWS Toolkit for .NET CLI (Amazon.Lambda.Tools)
https://github.com/aws/aws-extensions-for-dotnet-cli.NET Templates for AWS Lambda
https://docs.aws.amazon.com/lambda/latest/dg/csharp-package-cli.htmlDeploying .NET Lambda Functions
https://docs.aws.amazon.com/lambda/latest/dg/csharp-deployment-package.htmlTesting AWS Lambda Functions Locally
https://docs.aws.amazon.com/lambda/latest/dg/images-test.htmlAWS Lambda + API Gateway Integration
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-getting-started-with-rest-apis.html.NET on AWS – Official AWS Page
https://aws.amazon.com/net/




