Serverless .Net Core(2.0) application with AWS Lambda: Step by step guide

aws15

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
  • Serverless applications 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
  • 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
  • .Net Core 2.0 SDK from here (I have written a post to install SDK here)
  • AWS 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:

aws1

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):

aws2

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

aws3

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

aws4

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
  • New LambdaEntryPoint.cs 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
  • 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:

aws5

Deploy the application to AWS Lambda

Let us deploy our application.

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

aws6

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

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

aws7

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:

aws8

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):

aws9

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):

aws11

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

aws12

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

aws12

This link is nothing but your applications’ URL.

Click on the URL:

aws13

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

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

aws14

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

Hope it helps.

 

 

 

14 thoughts on “Serverless .Net Core(2.0) application with AWS Lambda: Step by step guide

  1. Hi, not sure if it’s a risk but we can totally see your “blacked out” access keys and account information in that one picture.

    Like

  2. Just want to know if it is worth time spending on getting the app to Lambda. It is a software used on all computers.

    Like

Leave a comment