Note – You can find the source code of my sample application here.

Amazon has recently announced the .NET Core 2.0 AWS Lambda runtime.

In this post, we will see how to create Server less .Net Core 2.0 application using AWS Lambda.

Let us first see what is Serverless computing?

Serverless computing allows you to build and run applications and services without thinking about servers

allows you to build and run applications and services without thinking about servers Serverless applications don’t require you to provision, scale, and manage any servers

don’t require you to provision, scale, and manage any servers You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you

or and everything required to run and scale your application with high availability is handled for you Building serverless applications means that your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on-premises.

Let us start Step by step guide.

prerequisite:

Visual studio 2017 community edition, download here

community edition, download here .Net Core 2.0 SDK from here (I have written a post to install SDK here)

from here (I have written a post to install SDK here) AWS Free account here.

Free account here. AWS Toolkit for Visual Studio 2017 here

As mentioned above, install AWS toolkit for Visual Studio 2017 and once you install it successfully, it would show below screen when you open Visual Studio 2017:

AWS Serverless application in VS 2017

Next step is to create AWS Serverless application, for this, you can get the readymade templated under Create New Project -> Visual C# -> AWS Lambda -> AWS Serverless application(.Net Core):

Once you click on Ok, Blueprint selection page will open, in that select ASP.Net Core application and then click on Finish:

Once you click on Finish, Visual Studio will create a well-structured application for you:

If you look at the structure, it is almost similar to other .Net Core application structure but the differences are:

LocalEntryPoint.cs class instead of Program.cs class which is used to run the ASP.NET Core project locally

class instead of Program.cs class which is used to run the ASP.NET Core project locally New LambdaEntryPoint.cs class which is the entry point for Lambda functions and it extends APIGatewayProxyFunction

class which is the entry point for Lambda functions and it extends APIGatewayProxyFunction aws-lambda-tools-defaults.json – default argument settings for use with Visual Studio and command line deployment tools for AWS

– default for use with Visual Studio and command line deployment tools for AWS serverless.template – an AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources

If you run the application locally, it would have landing page as below:

Deploy the application to AWS Lambda

Let us deploy our application.

Right click on solution and click on Publish to AWS Lambda:

The next window will ask for the details of the serverless application.

Click Add another account icon which will ask for below details:

You can get the Access key details by clicking on My security credentials -> Access keys (access key ID and secret access key) -> Create new access key on your AWS console.

Once the key is generated, you can either see the keys or you can download the keys:

Go back to Visual Studio and add Access key Id, Secret Access key, Profile Name, Account Number(You can find it under My Account tab):

Once you click on Ok, it will fetch the details from your AWS account.

Add new bucket if you do not have any buckets(note that you can use different IAM users as well):

Once you click on Publish, the creation of the AWS CloudFormation stack is initiated:

Once the creation is completed, the AWS CloudFormation stack view is launched. It contains the AWS Serverless URL:

This link is nothing but your applications’ URL.

Click on the URL:

Congratulations, your application is now hosted on AWS and it is serverless.

You can check your application in S3 bucket on AWS console:

Note – You can find the source code of my sample application here.

Hope it helps.