Skip to main content

Command Palette

Search for a command to run...

Running .NET on AWS Lambda: A Quick Start Guide

Updated
3 min read
Running .NET on AWS Lambda: A Quick Start Guide
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.

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:

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:

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

CloudSharp

Part 4 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.

Start from the beginning

CI/CD Pipeline for .NET Lambdas Using GitHub Actions

Serverless applications in .NET are growing in popularity thanks to AWS Lambda’s support for .NET 6, .NET 7, and now .NET 8. But building, testing, and deploying these applications manually can be time-consuming and error-prone. That’s where CI/CD pi...

More from this blog

C

Code With Renato

15 posts