Skip to content

Latest commit

 

History

History
194 lines (141 loc) · 11.7 KB

functions-create-first-function-vs-code.md

File metadata and controls

194 lines (141 loc) · 11.7 KB
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

Quickstart: Create a function in Azure using Visual Studio Code

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

Configure your environment

Before you get started, make sure you have the following requirements in place:

::: zone pivot="programming-language-csharp,programming-language-powershell,programming-language-python"

Create your local project

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.

  1. Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project... icon.

    Choose Create a new project

  2. 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.

  3. 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.

  4. 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]

Run the function in Azure

  1. 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.

    Copy the function URL for the new HTTP trigger

  2. 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:

    Function response in the browser

Clean up resources

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.

Next steps

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