From 9f7dc8d8102366d4ca2d0234b56010ba79b907b4 Mon Sep 17 00:00:00 2001 From: Glenn Gailey Date: Fri, 6 Sep 2024 11:17:08 -0700 Subject: [PATCH] add links to QS article --- README.md | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0951c1b..ea14583 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ --- -name: Azure Functions Python HTTP Trigger using azd -description: This repository contains an Azure Functions HTTP trigger quickstart written in Python and deployed to Azure Functions Flex Consumption using the Azure Developer CLI (azd). This sample uses managed identity and a virtual network to make sure it's secure by default. +name: Azure Functions Python HTTP Trigger using Azure Developer CLI +description: This repository contains an Azure Functions HTTP trigger quickstart written in Python and deployed to Azure Functions Flex Consumption using the Azure Developer CLI (azd). The sample uses managed identity and a virtual network to make sure deployment is secure by default. page_type: sample languages: - azdeveloper @@ -13,17 +13,19 @@ products: urlFragment: functions-quickstart-python-azd --- -# Azure Functions Python HTTP Trigger using AZD +# Azure Functions Python HTTP Trigger using Azure Developer CLI -This repository contains an Azure Functions HTTP trigger quickstart written in Python and deployed to Azure using Azure Developer CLI (AZD). This sample uses managed identity and a virtual network to insure it's secure by default. +This template repository contains an HTTP trigger reference sample for Azure Functions written in Python and deployed to Azure using the Azure Developer CLI (`azd`). The sample uses managed identity and a virtual network to make sure deployment is secure by default. + +This source code supports the article [Quickstart: Create and deploy functions to Azure Functions using the Azure Developer CLI](https://learn.microsoft.com/azure/azure-functions/create-first-function-azure-developer-cli?pivots=programming-language-python). ## Prerequisites + [Python 3.11](https://www.python.org/) -+ [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools) ++ [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local?pivots=programming-language-python#install-the-azure-functions-core-tools) + [Azure Developer CLI (AZD)](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd) + To use Visual Studio Code to run and debug locally: - + [Visual Studio Code](https://code.visualstudio.com/) + + [Visual Studio Code](https://code.visualstudio.com/) + [Azure Functions extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions) ## Initialize the local project @@ -38,13 +40,15 @@ You can initialize a project from this `azd` template in one of these ways: Supply an environment name, such as `flexquickstart` when prompted. In `azd`, the environment is used to maintain a unique deployment context for your app. -+ Fork this repository to your GitHub account and then clone locally using the `git clone` command: ++ Clone the GitHub template repository locally using the `git clone` command: ```shell - git clone https://github.com//functions-quickstart-python-azd.git + git clone https://github.com/Azure-Samples/functions-quickstart-python-azd.git cd functions-quickstart-python-azd ``` + You can also clone the repository from your own fork in GitHub. + ## Prepare your local environment Add a file named `local.settings.json` in the root of your project with the following contents: @@ -64,14 +68,14 @@ Add a file named `local.settings.json` in the root of your project with the foll The way that you create your virtual environment depends on your operating system. Open the terminal, navigate to the project folder, and run these commands: -### Linux/macOS +### Linux/macOS/bash ```bash python -m venv .venv source .venv/bin/activate ``` -#### Windows +#### Windows (Cmd) ```shell py -m venv .venv @@ -80,21 +84,25 @@ py -m venv .venv ## Run your app from the terminal -1. Run these commands in the virtual environment: +1. To start the Functions host locally, run these commands in the virtual environment: ```shell pip3 install -r requirements.txt func start ``` -2. From your HTTP test tool in a new terminal (or from your browser), call the HTTP GET endpoint: +1. From your HTTP test tool in a new terminal (or from your browser), call the HTTP GET endpoint: -3. Test the HTTP POST trigger with a payload using your favorite secure HTTP test tool. This example uses the `curl` tool with payload data from the [`testdata.json`](./testdata.json) project file: +1. Test the HTTP POST trigger with a payload using your favorite secure HTTP test tool. This example uses the `curl` tool with payload data from the [`testdata.json`](./testdata.json) project file: ```shell curl -i http://localhost:7071/api/httppost -H "Content-Type: text/json" -d @testdata.json ``` +1. When you're done, press Ctrl+C in the terminal window to stop the `func.exe` host process. + +1. Run `deactivate` to shut down the virtual environment. + ## Run your app using Visual Studio Code 1. Open the root folder in a new terminal. @@ -104,7 +112,9 @@ py -m venv .venv ## Source Code -The source code for both functions is in `function_app.py` code file. The function is identified as an Azure Function by use of the `@azure/functions` library. This code shows an HTTP GET triggered function. +The source code for both functions is in the [`function_app.py`](./function_app.py) code file. Azure Functions requires the use of the `@azure/functions` library. + +This code shows an HTTP GET triggered function: ```python @app.route(route="httpget", methods=["GET"]) @@ -116,7 +126,7 @@ def http_get(req: func.HttpRequest) -> func.HttpResponse: return func.HttpResponse(f"Hello, {name}!") ``` -This code shows an HTTP POST triggered function. +This code shows an HTTP POST triggered function: ```python @app.route(route="httppost", methods=["POST"]) @@ -154,10 +164,12 @@ You're prompted to supply these required deployment parameters: | Parameter | Description | | ---- | ---- | -| _Environment name_ | An environment that's used to maintain a unique deployment context for your app. You won't be prompted if you created the local project using `azd init`.| +| _Environment name_ | An environment that's used to maintain a unique deployment context for your app. You aren't prompted when you created the local project using `azd init`.| | _Azure subscription_ | Subscription in which your resources are created.| | _Azure location_ | Azure region in which to create the resource group that contains the new Azure resources. Only regions that currently support the Flex Consumption plan are shown.| +To learn how to obtain your new function endpoints in Azure along with the required function keys, see [Invoke the function on Azure](https://learn.microsoft.com/azure/azure-functions/create-first-function-azure-developer-cli?pivots=programming-language-java#invoke-the-function-on-azure) in the companion article [Quickstart: Create and deploy functions to Azure Functions using the Azure Developer CLI](https://learn.microsoft.com/azure/azure-functions/create-first-function-azure-developer-cli?pivots=programming-language-java#invoke-the-function-on-azure). + ## Redeploy your code You can run the `azd up` command as many times as you need to both provision your Azure resources and deploy code updates to your function app.