You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-create-first-function-python.md
+24-29Lines changed: 24 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ manager: gwallace
15
15
16
16
This article shows you how to use command-line tools to create a Python project that runs in Azure Functions. An HTTP request triggers the function you create. Finally, you publish your project to run as a [serverless function](functions-scale.md#consumption-plan) in Azure.
17
17
18
-
This article is the first of two quickstarts for Azure Functions. After you complete this article, you [add an Azure Storage queue output binding](functions-add-output-binding-storage-queue-python.md) to your function.
18
+
This article is the first of two Python quickstarts for Azure Functions. After you complete this quickstart, you can[add an Azure Storage queue output binding](functions-add-output-binding-storage-queue-python.md) to your function.
## Create and activate a virtual environment (optional)
35
35
36
-
To locally develop and test Python functions, it's recommended to use a Python 3.6.x environment. Run the following commands to create and activate a virtual environment named `.venv`.
36
+
You can use a Python 3.6.x environment to locally develop and test Python functions. Run the following commands to create and activate a virtual environment named `.venv`.
37
37
38
38
> [!NOTE]
39
39
> If Python didn't install venv on your Linux distribution, you can install it using the following command:
@@ -54,15 +54,11 @@ py -m venv .venv
54
54
.venv\scripts\activate
55
55
```
56
56
57
-
Now that the virtualenv is activated, you'll run the remaining commands in it. If you want to get out of the virtual environment, run this command:
57
+
Now that you activated the virtual environment, run the remaining commands in it. To get out of the virtual environment, run `deactivate`.
58
58
59
-
```console
60
-
deactivate
61
-
```
62
-
63
-
## Create a local Functions project
59
+
## Create a local functions project
64
60
65
-
A Functions project is the equivalent of a function app in Azure. It can have multiple functions that all share the same local and hosting configurations.
61
+
A functions project is the equivalent of a functionappin Azure. It can have multiple functions that all share the same local and hosting configurations.
66
62
67
63
1. In the virtual environment, run the following command:
68
64
@@ -74,9 +70,9 @@ A Functions project is the equivalent of a function app in Azure. It can have mu
74
70
75
71
The command creates a _MyFunctionProj_ folder. It contains these three files:
76
72
77
-
* `local.settings.json`: used to store app settings and connection strings when running locally. This file doesn't get published to Azure.
78
-
*`requirements.txt`: contains the list of packages the system will install on publishing to Azure.
79
-
*`host.json`: contains global configuration options that affect all functions in a functionapp. This file does get published to Azure.
73
+
**local.settings.json*: used to store app settings and connection strings when running locally. This file doesn't get published to Azure.
74
+
* *requirements.txt*: contains the list of packages the system will install on publishing to Azure.
75
+
* *host.json*: contains global configuration options that affect all functions in a function app. This file does get published to Azure.
80
76
81
77
1. Go to the new *MyFunctionProj* folder:
82
78
@@ -86,7 +82,7 @@ A Functions project is the equivalent of a function app in Azure. It can have mu
86
82
87
83
## Create a function
88
84
89
-
Now it's time to create a function for the new project.
85
+
Add a function to the new project.
90
86
91
87
1. To add a function to your project, run the following command:
92
88
@@ -100,25 +96,25 @@ Now it's time to create a function for the new project.
100
96
101
97
These commands create a subfolder named _HttpTrigger_. It contains the following files:
102
98
103
-
***function.json**: configuration file that defines the function, trigger, and other bindings. Take a look at this file. Notice that the value for`scriptFile` points to the file containing the function, while the system defines the invocation trigger and bindingsin the `bindings` array.
99
+
**function.json*: configuration file that defines the function, trigger, and other bindings. Notice that inthis file, the value for`scriptFile` points to the file containing the function, and the `bindings` array defines the invocation trigger and bindings.
104
100
105
101
Each binding requires a direction, type and a unique name. The HTTP trigger has an input binding of type [`httpTrigger`](functions-bindings-http-webhook.md#trigger) and output binding of type [`http`](functions-bindings-http-webhook.md#output).
106
102
107
-
***\_\_init\_\_.py**: script file that is your HTTP triggered function. Open the script. Take note that it contains a default `main()`. HTTP data from the trigger is passed to thisfunctionusing the `req` named binding parameter. Defined in function.json,`req` is an instance of the [azure.functions.HttpRequest class](/python/api/azure-functions/azure.functions.httprequest).
103
+
**\_\_init\_\_.py*: script file that is your HTTP triggered function. Notice that this script has a default `main()`. HTTP data from the trigger passes to thefunctionusing the `req` named `binding parameter`. The `req`, which is defined in function.json, is an instance of the [azure.functions.HttpRequest class](/python/api/azure-functions/azure.functions.httprequest).
108
104
109
105
The return object, defined as `$return`in*function.json*, is an instance of [azure.functions.HttpResponse class](/python/api/azure-functions/azure.functions.httpresponse). To learn more, see [Azure Functions HTTP triggers and bindings](functions-bindings-http-webhook.md).
110
106
111
107
## Run the function locally
112
108
113
-
The functionruns locally using the same Azure Functions runtime that is in Azure.
109
+
The functionruns locally using the Azure Functions runtime.
114
110
115
111
1. This command starts the functionapp:
116
112
117
113
```console
118
114
func host start
119
115
```
120
116
121
-
When the Functions host starts, it writes something like the following output. It's truncated so you can read it better:
117
+
When the Azure Functions host starts, it writes something like the following output. It's truncated here so you can read it better:
122
118
123
119
```output
124
120
@@ -150,11 +146,9 @@ The function runs locally using the same Azure Functions runtime that is in Azur
150
146
[8/27/2018 10:38:27 PM] Job host started
151
147
```
152
148
153
-
1. Copy the URL of your `HttpTrigger` function from the runtime output.
149
+
1. Copy the URL of your `HttpTrigger` function from the runtime output and paste it into your browser's address bar.
154
150
155
-
1. Paste it into your browser's address bar.
156
-
157
-
1. Append the query string `?name=<yourname>` to this URL and execute the request. The following screenshot shows the response in the browser to the GET request returned by the local function:
151
+
1. Append the query string `?name=<yourname>` to this URL and execute the request. The following screenshot shows the response to the GET request that the localfunctionreturns to the browser:
158
152
159
153

160
154
@@ -172,29 +166,30 @@ A function app provides an environment for executing your function code. It lets
172
166
173
167
Run the following command. Replace `<APP_NAME>` with a unique functionapp name. Replace `<STORAGE_NAME>` with a storage account name. The `<APP_NAME>` is also the default DNS domain forthe function app. This name needs to be unique across all appsin Azure.
174
168
169
+
> [!NOTE]
170
+
> You can't host Linux and Windows apps in the same resource group. If you have an existing resource group named `myResourceGroup` with a Windows function app or web app, you must use a different resource group.
171
+
175
172
```azurecli-interactive
176
173
az functionapp create --resource-group myResourceGroup --os-type Linux \
> You can't host Linux and Windows apps in the same resource group. If you have an existing resource group named `myResourceGroup` with a Windows function app or web app, you must use a different resource group.
182
177
183
-
This command will also provision an associated Azure Application Insights instance. It will be in the same resource group that you can use for monitoring and viewing logs.
178
+
The preceeding command will also provision an associated Azure Application Insights instance. It will be in the same resource group, which you can use for monitoring and viewing logs.
184
179
185
180
You're now ready to publish your local functions project to the functionappin Azure.
186
181
187
182
## Deploy the function app project to Azure
188
183
189
-
After the functionappis created in Azure, you can use the [func azure functionapp publish](functions-run-local.md#project-file-deployment) Core Tools command to deploy your project code to Azure. In these examples, replace `<APP_NAME>` with the name of your app from the previous step.
184
+
After you create the functionappin Azure, you can use the [func azure functionapp publish](functions-run-local.md#project-file-deployment) Core Tools command to deploy your project code to Azure. In this examples, replace `<APP_NAME>` with the name of your app.
Copy the `Invoke url` value foryour `HttpTrigger`. You can use it to test your functionin Azure. The URL contains a `code` query string value. It's your function key. This key makes it difficult for others to call your HTTP trigger endpoint in Azure.
208
+
You can copy the `Invoke url` value foryour `HttpTrigger` and use it to test your functionin Azure. The URL contains a `code` query string value that is your functionkey, which makes it difficult forothers to call your HTTP trigger endpointin Azure.
> To view near real-time logs for a published Python app, we recommend using the [Application Insights Live Metrics Stream](functions-monitoring.md#streaming-logs)
213
+
> To view near real-time logs for a published Python app, use the [Application Insights Live Metrics Stream](functions-monitoring.md#streaming-logs).
Copy file name to clipboardExpand all lines: includes/functions-create-resource-group.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,10 @@ ms.author: glenga
7
7
---
8
8
## Create a resource group
9
9
10
-
Create a resource group with the [az group create](/cli/azure/group). An Azure resource group is a logical container into which Azure resources like function apps, databases, and storage accounts are deployed and managed.
10
+
Create a resource group with the [az group create](/cli/azure/group#az-group-create) command. An Azure resource group is a logical container into which Azure resources like function apps, databases, and storage accounts are deployed and managed.
11
11
12
12
The following example creates a resource group named `myResourceGroup`.
13
-
If you are not using Cloud Shell, sign in first using `az login`.
13
+
If you aren't using Cloud Shell, sign in first using `az login`.
14
14
15
15
```azurecli-interactive
16
16
az group create --name myResourceGroup --location westeurope
Copy file name to clipboardExpand all lines: includes/functions-create-storage-account.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ ms.author: glenga
7
7
---
8
8
## Create an Azure Storage account
9
9
10
-
Functions uses a general-purpose account in Azure Storage to maintain state and other information about your functions. Create a general-purpose storage account in the resource group you created by using the [az storage account create](/cli/azure/storage/account) command.
10
+
Functions uses a general-purpose account in Azure Storage to maintain state and other information about your functions. Create a general-purpose storage account in the resource group you created by using the [az storage account create](/cli/azure/storage/account#az-storage-account-create) command.
11
11
12
12
In the following command, substitute a globally unique storage account name where you see the `<storage_name>` placeholder. Storage account names must be between 3 and 24 characters in length and may contain numbers and lowercase letters only.
Copy file name to clipboardExpand all lines: includes/functions-test-function-code.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,6 @@ Use cURL to test the deployed function. Using the URL, including the function ke
11
11
12
12

13
13
14
-
You can also paste the copied URL, including the function key, in to the address of your web browser. Again, append the query string `&name=<yourname>` to the URL before you execute the request.
14
+
You can also paste the copied URL, including the function key, into the address bar of your web browser. Again, append the query string `&name=<yourname>` to the URL before you execute the request.
15
15
16
16

0 commit comments