// TOM WARSOP

Creating and Deploying a C# AWS Lambda

2025/08/21
Tags: AWS Lambda C#

Introduction

The following tutorial goes through the basic steps required to write and deploy a C# based AWS Lambda. I won't be going into the detail of what Lambdas are, this will focus on the more practical aspect of writing one and deploying it to AWS. But for some context: AWS Lambda is Amazon's serverless compute service that allows you to run code without provisioning or managing servers.

Package References

You will need to add the Amazon.Lambda.Core package to the project you are going to write your Lambda in.

Lambda Code

The following acts as an example piece of code that will run in a Lambda, what it does isn't necessarily very important it's just being used to deomnstrate the key parts of the code required and then ultimately used in the deployment. As such it's just very simply logs out Hello World:

                        
using Amazon.Lambda.Core;

namespace MyFirstLambda
{
    public class MyFirstLambda
    {
        public void FunctionHandler(ILambdaContext context)
        {
            context.Logger.LogLine("Hello World");
        }
    }
}
                        
                    

The key part of the code here for the Lambda is the handler function - FunctionHandler. This is entry point for the Lambda. The signature for this function can vary, the one shown in the above example only passes in ILambdaContext which gives runtime information for the Lambda to access (request ID, memory limits, logger, etc.).

Deployment

To deploy the Lambda we can use a CLI-based Amazon tool, that can be installed using:

                        
dotnet tool install -g Amazon.Lambda.Tools
                        
                    

Then to deploy, navigate to the folder where your project file is located and run the following command (don't forget to dotnet build on the project first):

                        
dotnet lambda deploy-function
                        
                    

Running this deployment tool, you will be asked the following questions:

  • Which runtime you want. For C# we want to use the version of .net most appropriate, in this example I used: dotnet8.
  • The name you want for your Lambda (pick any you want).
  • To provide an IAM Role to provide AWS credentials to your code. You give an existing or create a new one here.
  • What memory size you want (in MB). For the example here I selected 128.
  • What timeout you want to give the Lambda (in seconds). For the example here I selected 60.
  • The name of the handler. This is of the format <Assembly>::<Namespace>.<Type>::<method>
  • . For example, for the above code I entered MyFirstLambda::MyFirstLambda.MyFirstLambda::FunctionHandler

After answering all the questions, the Lambda should be deployed and you can go and test in the AWS console.

The End