Azure - Create your first function using Visual Studio
Azure Functions lets you execute your code in a serverless environment without having to first create a VM or publish a web application.
In this article, you learn how to use the Visual Studio 2017 tools for Azure Functions to locally create and test a "hello world" function. You then publish the function code to Azure. These tools are available as part of the Azure development workload in Visual Studio 2017.
This topic includes a video that demonstrates the same basic steps.
Prerequisites
To complete this tutorial:
Install Visual Studio 2017 version 15.5 or a later version, including the Azure development workload.
If you have already installed Visual Studio, make sure you have installed any pending updates.
If you installed the Azure development workload with Visual Studio 2017 version 15.4 or earlier, you may also need to update your Azure Functions tools.
If you don't have an Azure subscription, create a free account before you begin.
Create a function app project
The Azure Functions project template in Visual Studio creates a project that can be published to a function app in Azure. A function app lets you group functions as a logical unit for management, deployment, and sharing of resources.
In Visual Studio, select New > Project from the File menu.
In the New Project dialog, select Installed, expand Visual C# > Cloud, select Azure Functions, type a Name for your project, and click OK. The function app name must be valid as a C# namespace, so don't use underscores, hyphens, or any other nonalphanumeric characters.
Use the settings specified in the table that follows the image.
Setting Suggested value Description Version Azure Functions v1
(.NET Framework)This creates a function project that uses the version 1 runtime of Azure Functions. The version 2 runtime, which supports .NET Core, is currently in preview. For more information, see How to target Azure Functions runtime version. Template HTTP trigger This creates a function triggered by an HTTP request. Storage account Storage Emulator An HTTP trigger doesn't use the Storage account connection. All other trigger types require a valid Storage account connection string. Access rights Anonymous The created function can be triggered by any client without providing a key. This authorization setting makes it easy to test your new function. For more information about keys and authorization, see Authorization keys in the HTTP and webhook bindings. - Click OK to create the function project and HTTP triggered function.
Visual Studio creates a project and in it a class that contains boilerplate code for the chosen function type. The FunctionName attribute on the method sets the name of the function. The HttpTrigger attribute specifies that the function is triggered by an HTTP request. The boilerplate code sends an HTTP response that includes a value from the request body or query string. You can add input and output bindings to a function by applying the appropriate attributes to the method. For more information, see the Triggers and bindings section of the Azure Functions C# developer reference.
Now that you've created your function project and an HTTP-triggered function, you can test it on your local computer.
Test the function locally
Azure Functions Core Tools lets you run an Azure Functions project on your local development computer. You are prompted to install these tools the first time you start a function from Visual Studio.
To test your function, press F5. If prompted, accept the request from Visual Studio to download and install Azure Functions Core (CLI) tools. You may also need to enable a firewall exception so that the tools can handle HTTP requests.
Copy the URL of your function from the Azure Functions runtime output.
Paste the URL for the HTTP request into your browser's address bar. Append the query string
?name=<yourname>
to this URL and execute the request. The following shows the response in the browser to the local GET request returned by the function:To stop debugging, press Shift + F5.
After you have verified that the function runs correctly on your local computer, it's time to publish the project to Azure.
Publish the project to Azure
You must have a function app in your Azure subscription before you can publish your project. You can create a function app right from Visual Studio.
In Solution Explorer, right-click the project and select Publish. Choose Create New and then Publish.
If you haven't already connected Visual Studio to your Azure account, select Add an account....
In the Create App Service dialog, use the Hosting settings as specified in the following table:
Setting Suggested value Description App Name Globally unique name Name that uniquely identifies your new function app. Subscription Choose your subscription The Azure subscription to use. Resource Group myResourceGroup Name of the resource group in which to create your function app. Choose New to create a new resource group. App Service Plan Consumption plan Make sure to choose the Consumption under Size after you click New to create a new plan. Also, choose a Location in a region near you or near other services your functions access. Note
An Azure storage account is required by the Functions runtime. Because of this, a new Azure Storage account is created for you when you create a function app.
Click Create to create a function app and related resources in Azure with these settings and deploy your function project code.
After the deployment is complete, make a note of the Site URL value, which is the address of your function app in Azure.
Test your function in Azure
Copy the base URL of the function app from the Publish profile page. Replace the
localhost:port
portion of the URL you used when testing the function locally with the new base URL. As before, make sure to append the query string?name=<yourname>
to this URL and execute the request.The URL that calls your HTTP triggered function should be in the following format:
Copyhttp://<functionappname>.azurewebsites.net/api/<functionname>?name=<yourname>
Paste this new URL for the HTTP request into your browser's address bar. The following shows the response in the browser to the remote GET request returned by the function:
Azure - Create your first function using Visual Studio的更多相关文章
- Create an offline installation of Visual Studio 2017 RC
Create an offline installation of Visual Studio 2017 RC 2016年12月7日 ...
- Azure ARM (7) ARM Template - 使用Visual Studio编辑
<Windows Azure Platform 系列文章目录> 之前介绍的ARM Template,都是使用文本编辑器来编辑JSON文件的. 文本讲介绍如何使用Visual Studio, ...
- Create C/C++ DLLs in Visual Studio
https://docs.microsoft.com/zh-tw/cpp/build/dlls-in-visual-cpp?view=vs-2019 Walkthrough: Create and u ...
- Create a Visual C++ Wizard for Visual Studio 2005
from:http://www.codeguru.com/cpp/v-s/devstudio_macros/customappwizards/article.php/c12775/Create-a-V ...
- [Azure] 使用 Visual Studio 2013 管理中国版 Azure 订阅
比较关心微软平台技术的朋友应该都知道,微软云服务(Microsoft Azure)以下简称Azure分为全球版和中国版,由于政府法规问题中国版的服务是由二十一世纪互联运营,整体来看中国版Azure和全 ...
- 使用 Visual Studio 将 ASP.NET Web 应用部署到 Azure
原文地址:https://www.azure.cn/zh-cn/documentation/articles/web-sites-dotnet-get-started 配置新的 Web 项目 下一步是 ...
- Visual Studio 2013 Update 3 RTM 正式发布
VS2013.3 RTM已发布! 完整安装包:http://download.microsoft.com/download/6/F/0/6F0777D3-3541-465F-8639-A8F9D36B ...
- Visual Studio 2019 正式发布,重磅更新,支持live share
如约而至,微软已于今天推出 Visual Studio 2019 正式版,一同发布的还有 Visual Studio 2019 for Mac. Visual Studio 2019 下载地址:htt ...
- Data Science With R In Visual Studio
R Projects Similar to Python, when we installed the data science tools we get an “R” section in our ...
随机推荐
- Java 重建二叉树 根据前序中序重建二叉树
题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2, ...
- DOM编程以及domReady加载的几种方式
1,关于DOM编程 DOM编程主要是对dom树节点进行操作,所以你必须掌握基本的节点类型,如何去获取节点名字以及值(这些相关知识你可以去网上查,这里推荐一个慕课学习网站->https ...
- keras & tensorflow 列出可用GPU 和 切换CPU & GPU
列出可用GPU from tensorflow.python.client import device_lib print(device_lib.list_local_devices()) from ...
- C#检查字符串是否是合法的HTTP URL地址的代码
在研发过程,把开发过程较好的一些内容片段记录起来,下面的内容是关于C#检查字符串是否是合法的HTTP URL地址的内容,应该是对各位有较大用处. protected string HTTPChecke ...
- Android的WebView调试工具(无需Fan墙,可同时调试多个设备,永不过期)
缘起 前端开发离不开Chrome的开发者工具,尤其是调试Android WebView时.然而,如果使用chrome://Inspect的方法,国内的开发者会惊奇地发现“空白啊”!为此,我发布过这个离 ...
- Android 屏幕适配插件 ScreenMatch
概述 ScreenMatch是根据你的需要,生成需要适配的尺寸的文件,手机会根据屏幕相关参数自动寻找合适的尺寸文件 添加插件 如图,打开Android Studio的Settings设置,找到Plug ...
- SQL Server捕获发生The query processor ran out of internal resources and could not produce a query plan...错误的SQL语句
最近收到一SQL Server数据库服务器的告警邮件,告警内容具体如下所示: DATE/TIME: 10/23/2018 4:30:26 PM DESCRIPTION: The query proc ...
- 5.机器学习——DBSCAN聚类算法
1.优缺点 优点: (1)聚类速度快且能够有效处理噪声点和发现任意形状的空间聚类: (2)与K-MEANS比较起来,不需要输入要划分的聚类个数: (3)聚类簇的形状没有偏倚: (4)可以在需要时输入过 ...
- 英语口语练习系列-C04-学校生活
连接到英语口语系列总分类 连接到上一章常用问句 登鹳雀楼 登鹳雀楼 唐代:王之涣 白日依山尽,黄河入海流. 欲穷千里目,更上一层楼. He is a fraternity brother. 他是兄弟会 ...
- ideal中项目resources下txt文件读取不到的问题。
这次做项目,原来用到了一个txt文件,在ideal中项目启动后报读取不到txt文件.项目原来是在eclipse中的. 在网上找了些文章,发现ideal中要读取到resources下的文件需要加上下面红 ...