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:
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
- 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:
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.
Reblogged this on Razin's Tech blog.
LikeLike
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.
LikeLike
Hey, I checked the picture again but I can’t see the keys. Can you please tell which
picture you are talking about?
LikeLike
This picture: https://neelbhatt40.files.wordpress.com/2018/01/aws91.png
If you zoom in (or higher the contrast) you can see that the black isn’t a solid/opaque black but slightly transparent.
LikeLike
This picture: https://neelbhatt40.files.wordpress.com/2018/01/aws91.png
If you zoom in and (higher the contrast) you can see that the black isn’t a solid/opaque black but slightly transparent.
(For example the Access Key ID continues with “AKIAIXKNZT…”. I dont want to post everything; just as proof)
LikeLike
Thanks for pointing out. I have deactivated the keys already so it will not create any problems.
LikeLike
That looks nice. Can a Windows .exe application be used to run in lambda if i have the source code.
LikeLike
Hey, I have not tried that yet but this may help you : https://stackoverflow.com/questions/49390759/communication-between-amazon-lambda-and-windows-application, https://stackoverflow.com/questions/36435092/possible-to-run-scheduled-exe-on-aws
LikeLike
Just want to know if it is worth time spending on getting the app to Lambda. It is a software used on all computers.
LikeLike
I have answered in your above comment.
LikeLike