Azure Function & AWS Function With C#
Using C# with Azure Functions
Two important prerequisites need to be met to build Azure Functions applications with C#:
- Have an active Microsoft Azure subscription. If you don’t have one already, you cancreate a free account.
- Get an Azure Storage account. If you don’t have this too, you can create a storage account by signing into the Azure portal.
As a C# developer, you are already familiar with the various tools for building your applications which include Visual Studio Code and Visual Studio IDE. Both tools help create applications with Azure Functions, depending on whichever one you are most comfortable with.
Let’s dig a little deeper into these two tools:

Visual Studio Code
Visual Studio Code is a lightweight but powerful code editor with different versions available for Windows, Linux, and MacOS.
To build apps for Azure functions, you will need to get Azure Tools for Visual Studio Code which will give you convenient commands through which you can access or create resources directly from the VS Code editor.
To set up Azure Tools, install theAzure Extension Pack by firing up your editor and navigating to the extension marketplace on the left side menu. The extension marketplace interface in VS Code should look like this:
When you are done with the setup of Azure for VS Code, login to Azure from the code editor by firing the Command Palette with the commands CTRL+Shift+P and typing “Azure: Login” in the text field that appears. Click the corresponding result that appears and a code will be generated by the editor with instructions on how to complete the process.
Another important extension if you will be developing in C# with VS Code is the C# for Visual Studio Code. As at the time of this writing, the extension supports basic debugging capabilities full details of which can be found here.

Visual Studio 2017 IDE
From version 15.5, Azure Development workload comes bundled with Azure Functions tools. This implies if you plan on installing the latest version of Visual Studio 2017, you need to include Azure Development workload in your installation process.
Your installation window should look like this:
Once installation is complete, sign in to your Microsoft account in Visual Studio and create a new Azure Functions project and you are good to go.

Now that we’ve highlighted what you need to know if you want to build serverless functions in C# with Azure functions, let’s move over to discussing what you need to begin running serverless apps on the AWS Lambda serverless framework.

Using C# with AWS Lambda
AWS Lambda is the compute part of the AWS serverless architecture, but contains zero administration. It is one of the most popular options for serverless and though it was launched by AWS in 2014, support for the .NET Core 1.0 runtime was announced in 2016 and the .NET Core 2.0 runtime in 2018. At this point, it is important to note .NET Core is different from the .NET framework and here are a few reasons AWS chose .NET Core over the .NET framework:
- .NET Core is the new redesigned version of .NET that focuses on more modern applications and in particular, cloud-enabled applications which has significant benefits when writing Lambda functions
- .NET Core was designed with a modularized design which means you only get to include the part of .NET you will need when writing your Lambda functions. This leads to lesser memory usage and since Lambda charges you for memory usage, lesser memory demands by your functions will lead to lesser costs to you for using AWS Lambda.
- .NET Core is open-source and has been validated against Amazon Linux — the underlying platform for AWS Lambda making it very possible for AWS to respond to security issues that might arise with using it.
- Lastly and more importantly, with .NET Core, you can now write your C# code on any platform as opposed to earlier days with .NET where you could write C# code on only Windows environments
To begin building Lambda functions in C# with Visual Studio you will need to understand AWS Lambda has a laid-down pattern for authoring code for your Lambda function. This pattern includes the following concepts:
- Handler - the handler function is a function called by AWS Lambda to begin execution of your Lambda function. AWS Lambda passes any input data into this function as the first parameter and passes a context object as a second parameter.
- Context Object - is the second parameter passed into the handler function and it provides information through which your code interacts with AWS Lambda.
- Logging - a good logging system is an important component of a well-written function. AWS Lambda writes these logs to CloudWatch Logs.
- Exceptions
Now that we know the framework for writing for AWS Lambda, let’s see how all this work together.
Writing C# Code for AWS Lambda with Visual Studio
A few prerequisites are required to begin writing code for Lambda functions:
- Have an AWS account. If you don’t have one, you can create an AWS account here
- Download and Install Visual Studio IDE 2017.
Note: older versions of Visual Studio will require an additional installation of .NET Core for Windows
- Download and Install the AWS Toolkit for Visual Studio
Once you’ve installed all prerequisites, open Visual Studio and fill in the AWS credentials on the Getting Started with the AWS Toolkit for Visual Studio window displayed next to the Start Page tab. The credentials (Access Key and Secret Key) can be gotten by following the instructions outlined in the window

With that all set, let’s move on to build our Lambda project.
Create a .NET Core Lambda Project
- Open Visual Studio IDE and go to File > New > Project
- On the Installed Pane, Click Visual C# and then AWS Lambda Project (.NET Core) as shown below:
- Fill out the project name with a name of your choice and click OK, leaving the defaults as they then move on to selecting the type of Lambda project you want to build.
- Click Finish to create the project and review the project code and structure.
- An important file created with your project is the aws-lambda-tools-defaults.json file where you set your function handler as well as other options. The contents of the file should look like this:
Publishing to AWS Lambda
The next step to running our code on AWS Lambda is to publish it. This is done after the code has been reviewed and you are convinced it is good to go. The following steps outline what you need to do to get your code published.
- On the right side, you can see the project. There in the Solution Explorer click Publish to AWS Lambda
- Next, fill in the Function Name in the Upload to AWS Lambda window that appears. You can give any preferred name to your function at this point. Once you are done, click Next.
- On the Advanced Function Details page, fill the Role Name section with a role associated with your AWS account. This is an important field to fill before we can proceed to the next stage of the upload process. Other sections include the VPC section (only useful if your function will be accessing resources on Amazon VPC) and the Environment section.
- Once your function begins uploading, a window is displayed showing the status of the upload after which a function view page is displayed where you can test your function and view logs respectively.
- The Invoke button begins testing the function while Log output displays output from the test. These logs are also saved into CloudWatch Logs in AWS where more details on the logs can be viewed.
Conclusion
Now, you have a quick peek into what you need to know to build and publish serverless applications with the powerful C# programming language. Though at Dashbird, we are more inclined towards AWS Lambda, there is nothing stopping you from exploring both the Microsoft Azure functions and AWS Lambda options in getting that serverless infrastructure for your applications.
Azure Function & AWS Function With C#的更多相关文章
- function,new function,Function,new Function 之间的区别
测试一: var fud01 = function() { var temp = 100; this.temp = 200; return temp + this.temp; } alert(typ ...
- (function(){...}())与(function(){...})()
(function(){ ...... }()) 或 (function(){ ...... })() 匿名函数自调用,也就是说,定义一个匿名函数 ...
- 浅析jQuery(function(){})与(function(){})(jQuery)之间的区别
本篇文章主要是对jQuery(function(){})与(function(){})(jQuery)之间的区别进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 Jquery是优秀的Javas ...
- jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解
1.(function($) {…})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){…} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...
- (function($){}) 和$(function(){}) 和$(function($){}) 区别
请问下(function($){}) 和$(function(){}) 和$(function($){}) 有什么区别 谢谢 一.先看 jQuery(function(){ }); 全写为 jQuer ...
- function foo(){}、(function(){})、(function(){}())等函数区别分析
前面一段时间,看到(function(){}),(function(){}())这些函数就犯晕,不知道它到底是什么意思,为什么函数外要加小括号,函数后要加小括号,加和不加到底有什么区别……一直犯迷糊, ...
- $(document).ready(function (){}) , $(function(){}) , $().ready(function(){}) , jquery(function(){}) , (function($){})(jquery)有什么区别
$(document).ready(function(){...}) , $().ready(function(){...}) , $(function(){...}) , jquery(funct ...
- $(function(){})与 (function(){})() (function($){})() 的区别
1. $(function(){ }) 或 jQuery(function(){ }) 此函数也可以写成 jQuery(function(){ }), 用于存放操作DOM对象的代码,执行其中代码时DO ...
- (function ( ){})( ) 与 (function ( ){}( )) 有什么区别?
js立即执行函数: (function ( ){})( ) 与 (function ( ){}( )) 有什么区别? 转自:http://www.jb51.net/article/75089.htm ...
随机推荐
- Spring学习(零):我们为什么要学习Spring
序言 通过使用Spring的IoC容器,可以对这些耦合关系(对Java代码而言)实现一个简单的文本化的操作:即是说通过一个或几个XML文文件,我们就可以方便的对应用对象的耦合关系进行浏览.修改和维护, ...
- K2开发中,遇到用户无权限OPEN当前的待办
1.用户有的时候在做操作时,提示用户没有权限OPEN当前流程,需要注意判断当前用户是K2标签还是K2SQL标签.如果标签不对,会导致当前问题的发生 后续如果再有碰到,再补充吧
- C# 中 equals( ) 和 == 的区别和用法
Equals: 下面的语句中,x.y 和 z 表示不为 null 的对象引用. * 除涉及浮点型的情况外,x.Equals(x) 都返回 true. * x.Equals(y) 返回与 y.Equal ...
- Mybatis-plus快速入门
简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 特性 无侵入:只做增强不做改变,引入它不会对现 ...
- [转]当CPU飙高时,它在做什么
在开发过程中,有时候我们发现JVM占用的CPU居高不下,跟我们的预期不符,这时,CPU在做什么呢?是什么线程让CPU如此忙碌呢?我们通过如下几步,可以查看CPU在执行什么线程. 1.查找jvm进程ID ...
- 学习笔记—XML
XML XML简介 XML指可扩展标记语言(EXtensible Markup Language),是一种标记语言. XML是一种灵活的语言,标签没有被预定义,需要自行定义标签. 通常,XML被用于信 ...
- C#打印模板设计,E店宝打印模板设置,winfrom打印模板设计,DevExpress.XtraReports.UI.XRTable 表格代码生成。
一.打印效果 二.代码编辑 1 .table1 : table控件的Name: 2.label33 :label控件 实现绑定[外部平台单号]的控件: 3.label32:绑定[E店宝订单编号](S开 ...
- 小程序应用的Python服务器部署高配,依然是腾讯云秒杀阿里云!
上一篇文章,“小程序创业最低配置部署,腾讯云折扣秒杀阿里云!”介绍了小程序项目启动时的最低配置服务器选择,但当项目良好发展时,还是要把服务器配置调整到标准水平,承受住日益增长的流量访问. 随着Pyth ...
- Easyui 关闭jquery-easui tab标签页前触发事件
关闭jquery-easui tab标签页前触发事件 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 需求场景 点击父页面tab 页关闭按钮时,需要做判断,判 ...
- SpringBoot 集成Apache Kafak 消息队列
Kafka is a distributed,partitioned,replicated commit logservice.它提供了类似于JMS的特性,但是在实现上完全不同,此外它并不是JMS规范 ...