.NET On AWS – Basics

Introduction

.NET platform can be used to build variety of different applications. You may be developing .NET applications for on-prem or azure cloud solutions. But you may not know that AWS is supporting and investing in .NET development for more than a decade.

In this post, we will learn the basics of .NET development and deployment on AWS.

Note: AWS highly recommends using .NET Core for development.

Initial Steps

There are many resources available on-line which will walk you through with some example of how to create and deploy a simple .NET Core Web API to AWS.

One particular resource I would like to mention is available on AWS Skill Builder – Getting Started with .NET Tutorial.

This tutorial will walk you through all the steps in your first journey to .NET on AWS.

Mainly you will need to download and install the AWS toolkit as a core step:

Download and install the AWS Toolkit for Visual Studio.

The AWS Toolkit for Visual Studio is an extension for Microsoft Visual Studio running on Microsoft Windows that makes it easier for developers to develop, debug, and deploy .NET applications using Amazon Web Services.

The AWS Toolkit for Visual Studio conveniently includes the AWS SDK for .NET, so you can get started building .NET applications on AWS infrastructure services in Visual Studio, including Amazon S3, Amazon EC2, AWS Elastic Beanstalk, and Amazon DynamoDB.

Once toolkit is installed, you can start by creating an AWS Serverless Application as shown next:

Create AWS Serverless Application

From Visual Studio, we can use the AWS Serverless Application template as shown below

Next, Select a Blueprint. As you can see there are different kind of AWS template to choose from. For our demo, I selected ASP.NET Core Web API template:

Here is our project created and shown in Solution Explorer

You can see that the structure is almost identical of typical .NET Core Web API application. However, it also has some AWS specific files, which act as a bridge when deploying this application to AWS Lambda.

Following is serverless.template file, which is actually an AWS SAM template (we will learn about this in later post).

For now, you can leave these files as is and we will cover those later.

API Controller

The template provides ValuesController and here I have created a new TokenController with a simple Get Method:

Because this is still a .NET Core application, we can simply debug it locally and here we can see the output of Get request to token endpoint:

So far, so good. Everything is like before as far as the typical code is written. Next lets publish this application to AWS.

Publish to AWS

We can simply select Publish to AWS Lambda option from the context menu as shown below:

This will ask to select the profile, stack name and S3 bucket as shown below:

I created a New S3 bucket (all these steps are explained in detail in the tutorial mentioned above)

Here we can see a stack creation is in progress and once done we can visit the AWS Serverless URL:

Here you can see the Get request made to the token endpoint:

Following picture shows AWS Web Console view of our application deployment:

Behind the scene, our API is deployed as Lambda function, which supports code in variety of languages including NodeJS, Python, Java, .NET etc.

In following picture, you can see the visual studio view (AWS Explorer):

API Gateway

When we published the .NET Core application, it also resulted in creation of an API Gateway API as shown below (this was setup in the SAM template when we created the application in visual studio)

As mentioned before, we will cover SAM templates in later posts, for now we can click the Name link and can see that it has following Resource/Method structure:

If we click the Any Method, we can see that its a Lambda function integration and function is our .NET Core application:

We can also click Stages Link and can see that two stages are also setup for the API automatically:

So, you can see that there is quite a stuff setup in AWS when we published the API from visual studio.

Related Items

We started with .NET on AWS and we saw that code writing part is just like always. However, now we are also looking at AWS services such as Lambda, API Gateway, S3 bucket, Stack etc.

If you are new to these topics, I will suggest to check the following posts which will provide you the background details and its gonna helpful as I am going to integrate these concepts/services in upcoming posts in .NET and AWS:

Some of the code examples, you will see in above mentioned posts will be written in NodeJS. Don’t worry much about the code part but rather focus on the AWS services itself.

Now, we will stop here for this post and will continue from here in the next post on this topic.

You can download the source code from this git repository.

Summary

AWS Toolkit and extensions made it very easy to deploy and run application on AWS. In this post, we took the first step and deploy a very simple API on AWS Lambda using visual studio.

You can also check .NET on AWS for latest news and updates.

Let me know, if you have some comments or questions. Till next time, Happy Coding.