Skip to content

Commit f70c4f6

Browse files
authored
Merge pull request #267266 from ggailey777/cleanup
[Functions] Python quickstart updates and other clean-up fixes
2 parents a4cb96b + 9d9b2f5 commit f70c4f6

24 files changed

+194
-694
lines changed

articles/azure-functions/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@
10151015
href: errors-diagnostics/diagnostic-events/azfd0010.md
10161016
- name: AZFD0011
10171017
href: errors-diagnostics/diagnostic-events/azfd0011.md
1018+
- name: AZFD0012
1019+
href: errors-diagnostics/diagnostic-events/azfd0012.md
10181020
- name: host.json 2.x reference
10191021
href: functions-host-json.md
10201022
- name: host.json 1.x reference

articles/azure-functions/create-first-function-cli-node.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ Each binding requires a direction, a type, and a unique name. The HTTP trigger h
159159
[!INCLUDE [functions-cleanup-resources-cli](../../includes/functions-cleanup-resources-cli.md)]
160160

161161
## Next steps
162-
162+
<!--- Revert this after we get Node.js v4 support added to the follow-on quickstarts -->
163+
::: zone pivot="nodejs-model-v3"
163164
> [!div class="nextstepaction"]
164165
> [Connect to an Azure Storage queue](functions-add-output-binding-storage-queue-cli.md?pivots=programming-language-javascript)
166+
::: zone-end
167+
::: zone pivot="nodejs-model-v4"
168+
> [!div class="nextstepaction"]
169+
> [Learn more about JavaScript functions](./functions-reference-node.md)
170+
::: zone-end

articles/azure-functions/create-first-function-cli-python.md

Lines changed: 28 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
---
22
title: Create a Python function from the command line - Azure Functions
33
description: Learn how to create a Python function from the command line, then publish the local project to serverless hosting in Azure Functions.
4-
ms.date: 02/16/2024
4+
ms.date: 02/29/2024
55
ms.topic: quickstart
66
ms.devlang: python
77
ms.custom: devx-track-python, devx-track-azurecli, devx-track-azurepowershell, mode-api, devdivchpfy22
8-
zone_pivot_groups: python-mode-functions
9-
108
---
119

1210
# Quickstart: Create a Python function in Azure from the command line
1311

1412
In this article, you use command-line tools 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.
1513

16-
This article covers both Python programming models supported by Azure Functions. Use the selector at the top to choose your programming model.
17-
18-
>[!NOTE]
19-
>The Python v2 programming model for Azure Functions provides a decorator-based approach for creating functions. To learn more about the Python v2 programming model, see the [Developer Reference Guide](functions-reference-python.md?pivots=python-mode-decorators).
14+
This article uses the Python v2 programming model for Azure Functions, which provides a decorator-based approach for creating functions. To learn more about the Python v2 programming model, see the [Developer Reference Guide](functions-reference-python.md?pivots=python-mode-decorators)
2015

2116
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
2217

@@ -35,12 +30,13 @@ Before you begin, you must have the following requirements in place:
3530
+ The Azure [Az PowerShell module](/powershell/azure/install-azure-powershell) version 5.9.0 or later.
3631

3732
+ [A Python version supported by Azure Functions](supported-languages.md#languages-by-runtime-version).
38-
::: zone pivot="python-mode-decorators"
33+
3934
+ The [Azurite storage emulator](../storage/common/storage-use-azurite.md?tabs=npm#install-azurite). While you can also use an actual Azure Storage account, the article assumes you're using this emulator.
40-
::: zone-end
4135

4236
[!INCLUDE [functions-install-core-tools](../../includes/functions-install-core-tools.md)]
4337

38+
Use the `func --version` command to make sure your version of Core Tools is at least `4.0.5530`.
39+
4440
## <a name="create-venv"></a>Create and activate a virtual environment
4541

4642
In a suitable folder, run the following commands to create and activate a virtual environment named `.venv`. Make sure that you're using a [version of Python supported by Azure Functions](supported-languages.md?pivots=programming-language-python#languages-by-runtime-version).
@@ -88,49 +84,7 @@ You run all subsequent commands in this activated virtual environment.
8884
## Create a local function
8985

9086
In Azure Functions, a function project is a container for one or more individual functions that each responds to a specific trigger. All functions in a project share the same local and hosting configurations.
91-
::: zone pivot="python-mode-configuration"
92-
In this section, you create a function project that contains a single function.
93-
94-
1. Run the [`func init`](functions-core-tools-reference.md#func-init) command as follows to create a Python functions project in the virtual environment.
95-
96-
```console
97-
func init --python --model V1
98-
```
99-
100-
The environment now contains various files for the project, including configuration files named [*local.settings.json*](functions-develop-local.md#local-settings-file) and [*host.json*](functions-host-json.md). Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file.
101-
102-
1. Add a function to your project by using the following command, where the `--name` argument is the unique name of your function (HttpExample) and the `--template` argument specifies the function's trigger (HTTP).
103-
104-
```console
105-
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
106-
```
107-
108-
[`func new`](functions-core-tools-reference.md#func-new) creates a subfolder matching the function name that contains a code file appropriate to the project's chosen language and a configuration file named *function.json*.
109-
110-
1. Run this command to make sure that the Azure Functions library is installed in the environment.
111-
112-
### [bash](#tab/bash)
113-
114-
```bash
115-
.venv/bin/python -m pip install -r requirements.txt
116-
```
117-
118-
### [PowerShell](#tab/powershell)
119-
120-
```powershell
121-
.venv\Scripts\python -m pip install -r requirements.txt
122-
```
123-
124-
### [Cmd](#tab/cmd)
125-
126-
```cmd
127-
.venv\Scripts\python -m pip install -r requirements.txt
128-
```
129-
130-
---
13187

132-
::: zone-end
133-
::: zone pivot="python-mode-decorators"
13488
In this section, you create a function project and add an HTTP triggered function.
13589

13690
1. Run the [`func init`](functions-core-tools-reference.md#func-init) command as follows to create a Python v2 functions project in the virtual environment.
@@ -148,53 +102,6 @@ In this section, you create a function project and add an HTTP triggered functio
148102
```
149103

150104
If prompted, choose the **ANONYMOUS** option. [`func new`](functions-core-tools-reference.md#func-new) adds an HTTP trigger endpoint named `HttpExample` to the `function_app.py` file, which is accessible without authentication.
151-
<!--- Remove these last steps after the next Core Tools version is released (4.28.0)--->
152-
1. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This setting is required for Functions to interpret your project correctly as the Python v2 model when running locally.
153-
154-
1. In the local.settings.json file, update the `AzureWebJobsStorage` setting as in the following example:
155-
156-
```json
157-
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
158-
```
159-
160-
This setting tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
161-
162-
1. Run this command to make sure that the Azure Functions library is installed in the environment.
163-
164-
### [bash](#tab/bash)
165-
166-
```bash
167-
.venv/bin/python -m pip install -r requirements.txt
168-
```
169-
170-
### [PowerShell](#tab/powershell)
171-
172-
```powershell
173-
.venv\Scripts\python -m pip install -r requirements.txt
174-
```
175-
176-
### [Cmd](#tab/cmd)
177-
178-
```cmd
179-
.venv\Scripts\python -m pip install -r requirements.txt
180-
```
181-
182-
---
183-
184-
## Start the storage emulator
185-
186-
By default, local development uses the Azurite storage emulator. This emulator is used when the `AzureWebJobsStorage` setting in the *local.settings.json* project file is set to `UseDevelopmentStorage=true`. When using the emulator, you must start the local Azurite storage emulator before running the function.
187-
188-
You can skip this step if the `AzureWebJobsStorage` setting in *local.settings.json* is set to the connection string for an Azure Storage account instead of `UseDevelopmentStorage=true`.
189-
190-
Use the following command to start the Azurite storage emulator in a separate process:
191-
192-
```cmd
193-
start azurite
194-
```
195-
196-
For more information, see [Run Azurite](../storage/common/storage-use-azurite.md?tabs=npm#run-azurite)
197-
::: zone-end
198105

199106
[!INCLUDE [functions-run-function-test-local-cli](../../includes/functions-run-function-test-local-cli.md)]
200107

@@ -210,14 +117,14 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
210117

211118
1. If needed, sign in to Azure.
212119

213-
# [Azure CLI](#tab/azure-cli)
120+
### [Azure CLI](#tab/azure-cli)
214121
```azurecli
215122
az login
216123
```
217124

218125
The [`az login`](/cli/azure/reference-index#az-login) command signs you into your Azure account.
219126

220-
# [Azure PowerShell](#tab/azure-powershell)
127+
### [Azure PowerShell](#tab/azure-powershell)
221128
```azurepowershell
222129
Connect-AzAccount
223130
```
@@ -226,18 +133,17 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
226133

227134
---
228135

229-
230136
1. Create a resource group named `AzureFunctionsQuickstart-rg` in your chosen region.
231137

232-
# [Azure CLI](#tab/azure-cli)
138+
### [Azure CLI](#tab/azure-cli)
233139

234140
```azurecli
235141
az group create --name AzureFunctionsQuickstart-rg --location <REGION>
236142
```
237143

238144
The [az group create](/cli/azure/group#az-group-create) command creates a resource group. In the above command, replace `<REGION>` with a region near you, using an available region code returned from the [az account list-locations](/cli/azure/account#az-account-list-locations) command.
239145

240-
# [Azure PowerShell](#tab/azure-powershell)
146+
### [Azure PowerShell](#tab/azure-powershell)
241147

242148
```azurepowershell
243149
New-AzResourceGroup -Name AzureFunctionsQuickstart-rg -Location '<REGION>'
@@ -247,23 +153,20 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
247153

248154
---
249155

250-
::: zone pivot="python-mode-decorators"
251-
::: zone-end
252-
253156
> [!NOTE]
254157
> You can't host Linux and Windows apps in the same resource group. If you have an existing resource group named `AzureFunctionsQuickstart-rg` with a Windows function app or web app, you must use a different resource group.
255158

256159
1. Create a general-purpose storage account in your resource group and region.
257160

258-
# [Azure CLI](#tab/azure-cli)
161+
### [Azure CLI](#tab/azure-cli)
259162

260163
```azurecli
261164
az storage account create --name <STORAGE_NAME> --location <REGION> --resource-group AzureFunctionsQuickstart-rg --sku Standard_LRS
262165
```
263166

264167
The [az storage account create](/cli/azure/storage/account#az-storage-account-create) command creates the storage account.
265168

266-
# [Azure PowerShell](#tab/azure-powershell)
169+
### [Azure PowerShell](#tab/azure-powershell)
267170

268171
```azurepowershell
269172
New-AzStorageAccount -ResourceGroupName AzureFunctionsQuickstart-rg -Name <STORAGE_NAME> -SkuName Standard_LRS -Location <REGION>
@@ -279,15 +182,15 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
279182

280183
1. Create the function app in Azure.
281184

282-
# [Azure CLI](#tab/azure-cli)
185+
### [Azure CLI](#tab/azure-cli)
283186

284187
```azurecli
285188
az functionapp create --resource-group AzureFunctionsQuickstart-rg --consumption-plan-location westeurope --runtime python --runtime-version <PYTHON_VERSION> --functions-version 4 --name <APP_NAME> --os-type linux --storage-account <STORAGE_NAME>
286189
```
287190

288191
The [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command creates the function app in Azure. You must supply `--os-type linux` because Python functions only run on Linux.
289192

290-
# [Azure PowerShell](#tab/azure-powershell)
193+
### [Azure PowerShell](#tab/azure-powershell)
291194

292195
```azurepowershell
293196
New-AzFunctionApp -Name <APP_NAME> -ResourceGroupName AzureFunctionsQuickstart-rg -StorageAccountName <STORAGE_NAME> -FunctionsVersion 4 -RuntimeVersion <PYTHON_VERSION> -Runtime python -Location '<REGION>'
@@ -303,15 +206,29 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
303206

304207
[!INCLUDE [functions-publish-project-cli](../../includes/functions-publish-project-cli.md)]
305208

306-
## Verify in Azure
209+
## Invoke the function on Azure
210+
211+
Because your function uses an HTTP trigger, you invoke it by making an HTTP request to its URL in the browser or with a tool like curl.
212+
213+
### [Browser](#tab/browser)
214+
215+
Copy the complete **Invoke URL** shown in the output of the `publish` command into a browser address bar, appending the query parameter `?name=Functions`. The browser should display similar output as when you ran the function locally.
216+
217+
### [curl](#tab/curl)
218+
219+
Run [`curl`](https://curl.haxx.se/) with the **Invoke URL** shown in the output of the `publish` command, appending the parameter `?name=Functions`. The output of the command should be the text, "Hello Functions."
220+
221+
---
307222

223+
<!--- // Re-enable this after this bug gets fixed: https://github.com/Azure/azure-functions-core-tools/issues/3609
308224
Run the following command to view near real-time streaming logs in Application Insights in the Azure portal.
309225

310226
```console
311227
func azure functionapp logstream <APP_NAME> --browser
312228
```
313229

314230
In a separate terminal window or in the browser, call the remote function again. A verbose log of the function execution in Azure is shown in the terminal.
231+
--->
315232

316233
[!INCLUDE [functions-cleanup-resources-cli](../../includes/functions-cleanup-resources-cli.md)]
317234

articles/azure-functions/create-first-function-vs-code-node.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,20 @@ Use the following table to resolve the most common issues encountered when using
170170
[!INCLUDE [functions-cleanup-resources-vs-code.md](../../includes/functions-cleanup-resources-vs-code-extension.md)]
171171

172172
## Next steps
173-
173+
<!--- Revert this after we get Node.js v4 support added to the follow-on quickstarts -->
174+
::: zone pivot="nodejs-model-v3"
174175
You have used [Visual Studio Code](functions-develop-vs-code.md?tabs=javascript) to create a function app with a simple HTTP-triggered function. In the next article, you expand that function by connecting to either Azure Cosmos DB or Azure Storage. To learn more about connecting to other Azure services, see [Add bindings to an existing function in Azure Functions](add-bindings-existing-function.md?tabs=javascript). If you want to learn more about security, see [Securing Azure Functions](security-concepts.md).
175176

176177
> [!div class="nextstepaction"]
177178
> [Connect to Azure Cosmos DB](functions-add-output-binding-cosmos-db-vs-code.md?pivots=programming-language-javascript)
178179
> [!div class="nextstepaction"]
179180
> [Connect to Azure Queue Storage](functions-add-output-binding-storage-queue-vs-code.md?pivots=programming-language-javascript)
181+
::: zone-end
182+
::: zone pivot="nodejs-model-v4"
183+
You have used [Visual Studio Code](functions-develop-vs-code.md?tabs=javascript) to create a function app with a simple HTTP-triggered function.
180184

185+
> [!div class="nextstepaction"]
186+
> [Learn more about JavaScript functions](./functions-reference-node.md)
187+
::: zone-end
181188
[Azure Functions Core Tools]: functions-run-local.md
182189
[Azure Functions extension for Visual Studio Code]: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions

0 commit comments

Comments
 (0)