Deploying .Net Lambda to AWS


Deploying .Net Lambda to AWS

Introduction:


We know how to create an AWS Lambda function in .Net in this tutorial: 

After we create the Lambda, we have to deploy it in the AWS. In this tutorial, let us see the various options available to deploy the .Net Lambda to AWS.

Prerequisites:

a. You need an AWS account.

b. Visual Studio.

c. Install AWS toolkit in Visual Studio.


Below is the first way to deploy Lambda.

a. Right-click on the project and select Publish to AWS Lambda.





b. If there is no profile setup, then set it up by entering the following details: These details of your account will be available from the IAM service in AWS.




c. After the details are entered, you will be navigated to the previous window:

d. This will publish the Lamda to the AWS S3 bucket. You can double-check by launching the AWS S3 service. Also, copy the S3 URL for the uploaded Lambda.

e. Navigate to Lamda service in AWS console. Enter Lambda name and Platform as .Net. Click on Create Function.


f. Click on Upload From and select Amazon S3 location.


g. Enter the URL copied in point d. Click Save. Lambda will be created.

The above method will not always work when you work on a production code in an organization. this is beacse the deployment should be usually done by DevOps team and they expect a package from developers so that they could use the package to deploy the Lambda. Letus discuss on another method of deploying the Lambda.

The next method is to create a zip file and upload the zip file. This is the easiest way of deploying the lambda.

First, we need to install an AWS lambda tool by running the following command in Visual Studio Command Prompt.

        dotnet tool install -g Amazon.Lambda.Tools

Secondly, run the below command, which will build the project.

dotnet build
Thirdly, run the below command to generate a zip file. The zip file will be generated and in the AWS web console, upload the zip instead of the S3 zip location.

dotnet lambda package

Happy coding :)