How to build AWS Lambda functions in .NET Core


Serverless computing has gained popularity in the last few years primarily because it supports both ease of development and high scalability. Serverless functions are stateless, event-driven, and highly scalable, and they don’t have any dependencies on the underlying infrastructure. AWS Lambda is the leading example of a serverless computing platform.

In this article, we’ll talk about how we can use .NET Core to build and deploy serverless functions on AWS Lambda. To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here. In addition, you will need the AWS Toolkit for Visual Studio 2019, which you can download here.

Naturally, you should also have an AWS account since we’ll be building and deploying our serverless functions to AWS Lambda. If you don’t have an AWS account, you can create a free one here.

AWS Lambda project types in Visual Studio

The AWS Toolkit for Visual Studio 2019 includes two .NET Core project templates that can help you build and deploy .NET Core-based AWS Lambda functions quickly. When working with AWS Lambda in Visual Studio, you can choose from either of two project types:

  1. AWS Lambda project: Select the AWS Lambda project type when you want to build and deploy an individual AWS Lambda function. We will leverage the AWS Lambda project type in this article to develop and deploy an AWS Lambda function.
  2. AWS Serverless Application project: Select the AWS Serverless Application project type if you’re developing multiple AWS Lambda functions that you will deploy together as part of an application, using an AWS CloudFormation template to orchestrate the deployment. For example, you could use this project type to create a database, add IAM roles, deploy several functions simultaneously.

Create a new AWS Lambda project in Visual Studio 2019

So let’s create an AWS Lambda project in Visual Studio 2019. Follow these steps to create a new AWS Lambda project leveraging .NET Core in Visual Studio 2019.

  1. Launch the Visual Studio IDE.
  2. Click on “Create a new project.”
  3. In the “Create a new project” window, search for and select the AWS Lambda Project (.NET Core – C#) template from the list of templates displayed.
  4. Click Next.
  5. In the “Configure your new project” window, specify the name and location for the new project.
  6. Optionally check the “Place solution and project in the same directory” check box, depending on your preferences.
  7. Click Create.
  8. Select the Empty Function blueprint. (See Figure 1.)
  9. Click Finish.
aws lambda net core 01 IDG

The AWS Toolkit for Visual Studio provides a number of quickstart blueprints for AWS Lambda projects.

A new AWS Lambda project will be created. Note that the project includes a file named Function.cs that contains the following code.

Copyright © 2021 IDG Communications, Inc.



Source link