# 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 to create, build, and deploy a .NET Lambda function using the AWS .NET tooling.

## Prerequisites

Before you start, make sure you have:

* [.NET SDK 6.0 or later](https://dotnet.microsoft.com/download)
    
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) (configured with credentials)
    
* [Amazon.Lambda.Tools](https://github.com/aws/aws-extensions-for-dotnet-cli)
    
* An AWS account
    

Install the Lambda tooling with:

```csharp
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:

```bash
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:

```csharp
public class Function
{
    public string FunctionHandler(string input, ILambdaContext context)
    {
        return $"Hello, {input}!";
    }
}
```

## Step 3: Test Locally

You can test the function locally with:

```bash
dotnet lambda invoke-function MyLambdaFunction --payload "World"
```

---

## Step 4: Deploy to AWS

Deploy using the Lambda tools:

```bash
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](https://console.aws.amazon.com/lambda/)
    
* Invoke it using the AWS CLI:
    

```bash
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:

```bash
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.html](https://docs.aws.amazon.com/lambda/latest/dg/dotnet.html)
    
* **AWS Toolkit for .NET CLI** (Amazon.Lambda.Tools)  
    [https://github.com/aws/aws-extensions-for-dotnet-cli](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.html](https://docs.aws.amazon.com/lambda/latest/dg/csharp-package-cli.html)
    
* **Deploying .NET Lambda Functions**  
    [https://docs.aws.amazon.com/lambda/latest/dg/csharp-deployment-package.html](https://docs.aws.amazon.com/lambda/latest/dg/csharp-deployment-package.html)
    
* **Testing AWS Lambda Functions Locally**  
    [https://docs.aws.amazon.com/lambda/latest/dg/images-test.html](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html)
    
* **AWS Lambda + API Gateway Integration**  
    [https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-getting-started-with-rest-apis.html](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/](https://aws.amazon.com/net/)
