Kien helps you build
a Lambda deployment package
for C# .NET

I created an AWS Lambda function in C#, but I get an error during invocation. How do I build my C# deployment package so that I don't get errors? What are my options?

Some common errors with Lambda functions in C# are "module not found," "module cannot be loaded," or "cannot find class." These errors might be caused by your deployment package having the wrong folder structure for the Lambda service to load your modules and libraries.  

Build a deployment package with the correct folder structure.

There are two main methods for building and deploying a C# deployment package for Lambda: using the .NET Core command line interface (CLI) with the Amazon.Lambda.Tools plugin, or using the AWS Toolkit for Visual Studio. For more information, see AWS Lambda Deployment Package in C#.

Build and deploy the package using the .NET Core CLI

1.    To install the default Lambda .NET templates and then add the Amazon.Lambda.Tools plugin to the .NET Core CLI, run the following command:

dotnet new -i 'Amazon.Lambda.Templates::*'

2.    Do one of the following:

To create a new Lambda function using one of the templates you installed, run the following command:

dotnet new lambda.EmptyFunction --name {function-name} --profile default --region {aws-region}

For example:

dotnet new lambda.EmptyFunction --name myFunction --profile default --region us-east-1

To add Amazon.Lambda.Tools to an existing project, manually add the following itemgroup to your project's 2017 .csproj file:

<DotNetCliToolReference Include="Amazon.Lambda.Tools" Version="{current-version}"></DotNetCliToolReference>

Note: Check the current version (for example, "3.1.1") of Amazon.Lambda.Tools on the NuGet website.

3.    To download all dependencies, run the following command:

cd {your-function-directory}
dotnet restore

For example:

cd myFunction\src\myFunction
dotnet restore

Note: If you get a "not compatible" error, make sure that you've installed a version of .NET Core that's compatible with Lambda tools, and that you're using that version in the CLI. To download older versions of .NET Core, see the .NET Download Archives website.

4.    To build the deployment package, run the following command:

dotnet lambda deploy-function

5.    When prompted in the CLI, enter a function name and select an IAM role. Your Lambda function is created.

Build and deploy the package using the AWS Toolkit for Visual Studio

1.    Download and install the AWS Toolkit for Visual Studio.

2.    Create and build an AWS Lambda Project (.NET Core) project. For more information, see Tutorial: Using the AWS Lambda Templates in the AWS Toolkit for Visual Studio and Create and Build a Project.

Check the function handler signature

The handler signature provided when you created your Lambda function should be in the following format:


For example:


To confirm that the function is formatted correctly, you can check the files under your function's src/{function-name} directory. For more information, see .NET Core CLI and Handler Signatures.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-12-27