title | description | ms.topic | ms.date | ms.custom | zone_pivot_groups |
---|---|---|---|---|---|
Create your first function in Azure using Visual Studio Code |
Create and publish to Azure a simple HTTP triggered function by using Azure Functions extension in Visual Studio Code. |
quickstart |
01/10/2020 |
mvc, devcenter, seo, tracking-python |
programming-languages-set-functions |
::: zone pivot="programming-language-csharp"
In this article, you use Visual Studio Code to create a C# class library-based function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
::: zone-end
::: zone pivot="programming-language-javascript"
In this article, you use Visual Studio Code to create a JavaScript function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
::: zone-end
::: zone pivot="programming-language-typescript"
In this article, you use Visual Studio Code to create a TypeScript function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
::: zone-end
::: zone pivot="programming-language-powershell"
In this article, you use Visual Studio Code to create a PowerShell function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
::: zone-end
::: zone pivot="programming-language-python"
In this article, you use Visual Studio Code to create a Python function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
::: zone-end
::: zone pivot="programming-language-java"
In this article, you use Visual Studio Code to create a Java function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
::: zone-end
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python" There's also a CLI-based version of this article. ::: zone-end ::: zone pivot="programming-language-java"
Note
If Visual Studio Code isn't your prefered development tool, check out our similar tutorials for Java developers using Maven, Gradle and IntelliJ IDEA. ::: zone-end
Before you get started, make sure you have the following requirements in place:
- An Azure account with an active subscription. Create an account for free.
::: zone pivot="programming-language-csharp,programming-language-powershell,programming-language-python"
-
Node.js, required by Windows for npm. Only Active LTS and Maintenance LTS versions. Use the
node --version
command to check your version. Not required for local development on macOS and Linux.
::: zone-end
::: zone pivot="programming-language-javascript,programming-language-typescript" -
Node.js, Active LTS and Maintenance LTS versions (10.14.1 recommended). Use the
node --version
command to check your version. ::: zone-end ::: zone pivot="programming-language-python" -
Python 3.8, Python 3.7, Python 3.6 are supported by Azure Functions (x64). ::: zone-end
::: zone pivot="programming-language-powershell" -
The .NET Core SDK 2.2+
::: zone-end
::: zone pivot="programming-language-java" -
The Java Developer Kit, version 8.
-
Apache Maven, version 3.0 or above. ::: zone-end
-
Visual Studio Code on one of the supported platforms.
::: zone pivot="programming-language-csharp" -
The C# extension for Visual Studio Code.
::: zone-end
::: zone pivot="programming-language-python" -
The Python extension for Visual Studio Code.
::: zone-end
::: zone pivot="programming-language-powershell" -
The PowerShell extension for Visual Studio Code. ::: zone-end
::: zone pivot="programming-language-java" -
The Java extension pack ::: zone-end
-
The Azure Functions extension for Visual Studio Code.
In this section, you use Visual Studio Code to create a local Azure Functions project in your chosen language. Later in this article, you'll publish your function code to Azure.
-
Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project... icon.
-
Choose a directory location for your project workspace and choose Select.
[!NOTE] These steps were designed to be completed outside of a workspace. In this case, do not select a project folder that is part of a workspace.
-
Provide the following information at the prompts:
::: zone pivot="programming-language-csharp"
-
Select a language for your function project: Choose
C#
. ::: zone-end ::: zone pivot="programming-language-javascript" -
Select a language for your function project: Choose
JavaScript
. ::: zone-end ::: zone pivot="programming-language-typescript" -
Select a language for your function project: Choose
TypeScript
. ::: zone-end ::: zone pivot="programming-language-powershell" -
Select a language for your function project: Choose
PowerShell
. ::: zone-end ::: zone pivot="programming-language-python" -
Select a language for your function project: Choose
Python
. -
Select a Python alias to create a virtual environment: Choose the location of your Python interpreter. If the location isn't shown, type in the full path to your Python binary.
::: zone-end
::: zone pivot="programming-language-java"
-
Select a language for your function project: Choose
Java
. -
Provide a group ID: Choose
com.function
. -
Provide an artifact ID: Choose
myFunction
. -
Provide a version: Choose
1.0-SNAPSHOT
. -
Provide a package name: Choose
com.function
. -
Provide an app name: Choose
myFunction-12345
. ::: zone-end
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python" -
Select a template for your project's first function: Choose
HTTP trigger
. -
Provide a function name: Type
HttpExample
. ::: zone-end
::: zone pivot="programming-language-csharp" -
Provide a namespace: Type
My.Functions
. ::: zone-end
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python" -
Authorization level: Choose
Anonymous
, which enables anyone to call your function endpoint. To learn about authorization level, see Authorization keys. ::: zone-end -
Select how you would like to open your project: Choose
Add to workspace
.
-
-
Using this information, Visual Studio Code generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. To learn more about files that are created, see Generated project files.
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-python,programming-language-java"
[!INCLUDE functions-run-function-test-local-vs-code]
::: zone-end
::: zone pivot="programming-language-powershell"
[!INCLUDE functions-run-function-test-local-vs-code-ps]
::: zone-end
After you've verified that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.
[!INCLUDE functions-sign-in-vs-code]
[!INCLUDE functions-publish-project-vscode]
-
Back in the Azure: Functions area in the side bar, expand the new function app under your subscription. Expand Functions, right-click (Windows) or Ctrl + click (macOS) on HttpExample, and then choose Copy function URL.
-
Paste this URL for the HTTP request into your browser's address bar, add the
name
query string as?name=Functions
to the end of this URL, and then execute the request. The URL that calls your HTTP-triggered function should be in the following format:http://<functionappname>.azurewebsites.net/api/httpexample?name=Functions
The following example shows the response in the browser to the remote GET request returned by the function:
When you continue to the next step, Add an Azure Storage queue binding to your function, you'll need to keep all your resources in place to build on what you've already done.
Otherwise, you can use the following steps to delete the function app and its related resources to avoid incurring any further costs.
[!INCLUDE functions-cleanup-resources-vs-code.md]
To learn more about Functions costs, see Estimating Consumption plan costs.
You have used Visual Studio Code to create a function app with a simple HTTP-triggered function. In the next article, you expand that function by adding an output binding. This binding writes the string from the HTTP request to a message in an Azure Queue Storage queue.
[!div class="nextstepaction"] Add an Azure Storage queue binding to your function