Deploying C# Application to a Serverless using AWS Lambda

Arda Batuhan Demir
6 min readSep 9, 2022

--

Introduction

What is AWS

Amazon Web Services (AWS) is a subsidiary of Amazon that provides on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. In aggregate, these cloud computing web services provide a set of primitive abstract technical infrastructure and distributed computing building blocks and tools.

What is AWS Lambda

AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. It is a computing service that runs code in response to events and automatically manages the computing resources required by that code. Node.js, Python, Java, Go, Ruby, and C# (through .NET Core) are all officially supported as of 2018.

Requirements

● Visual Studio IDE (2017 or 2019)

● AWS Account 1.4 Extensions

● AWS Toolkit for Visual Studio 2017 and 2019 1.5 Plugins

● AWSSDK.Core

● AWSSDK.Lambda

● Newstonsoft.Json

Configuration

Add AWS User

Identity management (ID management) is the organizational process for identifying, authenticating and authorizing individuals or groups of people to have access to applications, systems or networks by associating user rights and restrictions with established identities. Identity management (IdM) is the task of controlling information about users on computers. Such information includes information that authenticates the identity of a user, and information that describes information and actions they are authorized to access and/or perform. It also includes the management of descriptive information about the user and how and by whom that information can be accessed and modified. In addition to users, managed entities typically include hardware and network resources and even applications. 3 We need to add a user to publish our application on AWS Lambda, we will use that user to upload our program to AWS Lambda. To create a user go IAM service, click “Services” and search for IAM.

Click users on the left panel for user creation

Click add user button, we will use newly created user to publish our program on AWS Lambda

After than; Give a username to the user, and give “Programmatic Access”, our user does not need to access to the management console

Here we will attach policies to our user. Select “Administrator Access”, it will give all permissions. It’s more logical to give more specific policies

Add AWS Role

We need to give the role to delegate access to Lambda service. Go to IAM and click the role on the left.

Click the “Create Role” button to create a new role for ourselves.

Click “AWS Service” and “Lambda”. Here we are specifying the created role is for a AWS service, in our case its Lambda.

Add AWS Extension

To create AWS Lambda Project we need to have an extension called “AWS Toolkit for VisualStudio 2017 and 2019”

Click “Online” on the left panel, and search for keyword “aws” find “AWS Toolkit for VisualStudio 2017 and 2019” and click the “Download” button. You need to restart Visual Studio to extension installation

Add Plugins

We need to add “AWSSDK.Core”, “AWSSDK.Lambda”, “Microsoft.NetCore.App”, “Newtonsoft.json” plugins. To add them Right Click the dependencies and click Manage NuGet Packages

Click the Browse then find and install the “AWSSDK.Core”, “AWSSDK.Lambda”, “Microsoft.NetCore.App”, “Newtonsoft.json” plugins.

Enter plugin name to download. For example, in the search bar write “AWSSDK.Core” and press enter. After plugins are searched click the arrow icon to download that plugin. After download is complete we can use that plugin in our project.

Creating Lambda Project

First we need to create our project to upload our function to the AWS server. Hence, like creating a normal project we need to select File -> New -> Project

Like normal project creation you need to select type of the project (C# or C++ project). In this case we need to select “AWS Lambda” and “AWS Lambda Project(.NET Core — C#)”. Hence after we give our project a name and select location to save we can click the “OK” button to create a file.

After we click the “OK” button, we need to select a blueprint. In our case we will select “Empty Function” because we want to write our own function to run. Then we will press “Finish” to complete our project creation.

Add AWS Lambda Function to AWS

Before we added the AWS Lambda plugin to Visual Studio and wrote our function. Hence, we need to upload that function to AWS. First we need to find our project in “Solution Explorer” inside Visual Studio. Then we need to right click to our project to see options and click “Publish to AWS Lambda” like the picture below

After we click “Publish to AWS Lambda”, the page will be open like the below image. We need to connect our AWS account to the Visual Studio Plugin to upload our function. Hence we need to click human and plus sign picture to add our account.

After we click the human plus sign button, we need to enter our information to add our account. “Profile name” is whatever you want to enter. “For Access Key ID” and “Secret Access” Key we need to import the .csv file which we created and downloaded before.

After we add our account we need to select “Account profile to use” and enter our “Function Name” because the entered “Function Name” will be saved to the AWS systems. Then we can press the “Next” button to continue our process.

After pressing “Next” button. Page like below will be open. We need to select our role to give access to that function to what to do. As we remember we already created our custom role atAdd AWS Role. We select our custom role and will press the upload button to upload our function to the AWS system.

After uploading the function to the server, we can test it via Visual Studio. We need to enter data in Json format then click the “Invoke” button to see the result. Example picture like below.

--

--

Arda Batuhan Demir

5x AWS Cert* | Senior DevOps Engineer | Cloud Architect | AWS Community Builder