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-run-local.md
+69-50Lines changed: 69 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,21 +60,21 @@ The following steps use npm to install Core Tools on Windows. You can also use [
60
60
61
61
##### v2.x
62
62
63
-
```bash
63
+
```cmd
64
64
npm install -g azure-functions-core-tools
65
65
```
66
66
67
67
##### v3.x
68
68
69
-
```bash
69
+
```cmd
70
70
npm install -g azure-functions-core-tools@3
71
71
```
72
72
73
73
It may take a few minutes for npm to download and install the Core Tools package.
74
74
75
75
1. If you don't plan to use [extension bundles], install the [.NET Core 2.x SDK for Windows](https://www.microsoft.com/net/download/windows).
76
76
77
-
# [MacOS](#tab/macos)
77
+
# [macOS](#tab/macos)
78
78
79
79
The following steps use Homebrew to install the Core Tools on macOS.
80
80
@@ -158,33 +158,33 @@ Version 2.x requires you to select a default language for your project when it i
158
158
159
159
In the terminal window or from a command prompt, run the following command to create the project and local Git repository:
160
160
161
-
```bash
161
+
```
162
162
func init MyFunctionProj
163
163
```
164
164
165
165
When you provide a project name, a new folder with that name is created and initialized. Otherwise, the current folder is initialized.
166
166
In version 2.x, when you run the command you must choose a runtime for your project.
167
167
168
-
```output
168
+
<pre>
169
169
Select a worker runtime:
170
170
dotnet
171
171
node
172
172
python
173
173
powershell
174
-
```
174
+
</pre>
175
175
176
176
Use the up/down arrow keys to choose a language, then press Enter. If you plan to develop JavaScript or TypeScript functions, choose **node**, and then select the language. TypeScript has [some additional requirements](functions-reference-node.md#typescript).
177
177
178
178
The output looks like the following example for a JavaScript project:
@@ -257,13 +257,13 @@ Even when using the Microsoft Azure Storage Emulator for development, you may wa
257
257
258
258
To create a function, run the following command:
259
259
260
-
```bash
260
+
```
261
261
func new
262
262
```
263
263
264
264
In version 2.x, when you run `func new` you are prompted to choose a template in the default language of your function app, then you are also prompted to choose a name for your function. In version 1.x, you are also prompted to choose the language.
265
265
266
-
```output
266
+
<pre>
267
267
Select a language: Select a template:
268
268
Blob trigger
269
269
Cosmos DB trigger
@@ -274,18 +274,18 @@ SendGrid
274
274
Service Bus Queue trigger
275
275
Service Bus Topic trigger
276
276
Timer trigger
277
-
```
277
+
</pre>
278
278
279
279
Function code is generated in a subfolder with the provided function name, as you can see in the following queue trigger output:
280
280
281
-
```output
281
+
<pre>
282
282
Select a language: Select a template: Queue trigger
You can also specify these options in the command using the following arguments:
291
291
@@ -298,62 +298,65 @@ You can also specify these options in the command using the following arguments:
298
298
299
299
For example, to create a JavaScript HTTP trigger in a single command, run:
300
300
301
-
```bash
301
+
```
302
302
func new --template "Http Trigger" --name MyHttpTrigger
303
303
```
304
304
305
305
To create a queue-triggered function in a single command, run:
306
306
307
-
```bash
307
+
```
308
308
func new --template "Queue Trigger" --name QueueTriggerJS
309
309
```
310
310
311
311
## <a name="start"></a>Run functions locally
312
312
313
-
To run a Functions project, run the Functions host. The host enables triggers forall functionsin the project.
313
+
To run a Functions project, run the Functions host. The host enables triggers for all functions in the project. The start command varies, depending on your project language.
314
314
315
-
### Version 2.x
315
+
# [C\#](#tab/csharp)
316
316
317
-
In version 2.x of the runtime, the start command varies, depending on your project language.
318
-
319
-
#### C\#
320
-
321
-
```command
317
+
```
322
318
func start --build
323
319
```
320
+
# [JavaScript](#tab/node)
321
+
322
+
```
323
+
func start
324
+
```
324
325
325
-
#### JavaScript
326
+
# [Python](#tab/python)
326
327
327
-
```command
328
+
```
328
329
func start
329
330
```
331
+
This command must be [run in a virtual environment](/azure/azure-functions/functions-create-first-azure-function-azure-cli?pivots=programming-language-python#create-venv).
330
332
331
-
#### TypeScript
333
+
# [TypeScript](#tab/ts)
332
334
333
-
```command
335
+
```
334
336
npm install
335
337
npm start
336
338
```
337
339
338
-
### Version 1.x
339
-
340
-
Version 1.x of the Functions runtime requires the `host` command, as in the following example:
340
+
---
341
341
342
-
```command
343
-
func host start
344
-
```
342
+
>[!NOTE]
343
+
> Version 1.x of the Functions runtime requires the `host` command, as in the following example:
|**`--no-build`**| Do no build current project before running. For dotnet projects only. Default is set to false. Version 2.x only. |
351
-
|**`--cert`**| The path to a .pfx file that contains a private key. Only used with `--useHttps`. Version 2.x only. |
352
-
|**`--cors-credentials`**| Allow cross-origin authenticated requests (i.e. cookies and the Authentication header) Version 2.x only. |
353
+
| **`--no-build`** | Do no build current project before running. For dotnet projects only. Default is set to false. Not supported for version 1.x. |
354
+
| **`--cert`** | The path to a .pfx file that contains a private key. Only used with `--useHttps`. Not supported for version 1.x. |
355
+
| **`--cors-credentials`** | Allow cross-origin authenticated requests (i.e. cookies and the Authentication header) Not supported for version 1.x. |
353
356
| **`--cors`** | A comma-separated list of CORS origins, with no spaces. |
354
-
|**`--language-worker`**| Arguments to configure the language worker. For example, you may enable debugging for language worker by providing [debug port and other required arguments](https://github.com/Azure/azure-functions-core-tools/wiki/Enable-Debugging-for-language-workers). Version 2.x only. |
357
+
| **`--language-worker`** | Arguments to configure the language worker. For example, you may enable debugging for language worker by providing [debug port and other required arguments](https://github.com/Azure/azure-functions-core-tools/wiki/Enable-Debugging-for-language-workers). Not supported for version 1.x. |
355
358
| **`--nodeDebugPort`**, **`-n`** | The port for the Node.js debugger to use. Default: A value from launch.json or 5858. Version 1.x only. |
356
-
|**`--password`**| Either the password or a file that contains the password for a .pfx file. Only used with `--cert`. Version 2.x only. |
359
+
| **`--password`** | Either the password or a file that contains the password for a .pfx file. Only used with `--cert`. Not supported for version 1.x. |
357
360
| **`--port`**, **`-p`** | The local port to listen on. Default value: 7071. |
358
361
| **`--pause-on-error`** | Pause for additional input before exiting the process. Used only when launching Core Tools from an integrated development environment (IDE).|
359
362
| **`--script-root`**, **`--prefix`** | Used to specify the path to the root of the function app that is to be run or deployed. This is used for compiled projects that generate project files into a subfolder. For example, when you build a C# class library project, the host.json, local.settings.json, and function.json files are generated in a *root* subfolder with a path like `MyProject/bin/Debug/netstandard2.0`. In this case, set the prefix as `--script-root MyProject/bin/Debug/netstandard2.0`. This is the root of the function app when running in Azure. |
@@ -362,13 +365,13 @@ func host start
362
365
363
366
When the Functions host starts, it outputs the URL of HTTP-triggered functions:
364
367
365
-
```output
368
+
<pre>
366
369
Found the following functions:
367
370
Host.Functions.MyHttpTrigger
368
371
369
372
Job host started
370
373
Http Function MyHttpTrigger: http://localhost:7071/api/MyHttpTrigger
371
-
```
374
+
</pre>
372
375
373
376
>[!IMPORTANT]
374
377
>When running locally, authorization isn't enforced for HTTP endpoints. This means that all local HTTP requests are handled as `authLevel = "anonymous"`. For more information, see the [HTTP binding article](functions-bindings-http-webhook-trigger.md#authorization-keys).
@@ -392,21 +395,31 @@ Make sure to use the same server name and port that the Functions host is listen
392
395
393
396
The following cURL command triggers the `MyHttpTrigger` quickstart function from a GET request with the _name_ parameter passed in the query string.
The following example is the same function called from a POST request passing _name_ in the request body:
400
403
404
+
# [Bash](#tab/bash)
401
405
```bash
402
406
curl --request POST http://localhost:7071/api/MyHttpTrigger --data '{"name":"Azure Rocks"}'
403
407
```
408
+
# [Cmd](#tab/cmd)
409
+
```cmd
410
+
curl --request POST http://localhost:7071/api/MyHttpTrigger --data "{'name':'Azure Rocks'}"
411
+
```
412
+
---
404
413
405
414
You can make GET requests from a browser passing data in the query string. For all other HTTP methods, you must use cURL, Fiddler, Postman, or a similar HTTP testing tool.
406
415
407
416
#### Non-HTTP triggered functions
408
417
409
-
For all kinds of functions other than HTTP triggers and webhooks, you can test your functions locally by calling an administration endpoint. Calling this endpoint with an HTTP POST request on the local server triggers the function. You can optionally pass test data to the execution in the body of the POST request. This functionality is similar to the **Test** tab in the Azure portal.
418
+
For all kinds of functions other than HTTP triggers and webhooks and Event Grid triggers, you can test your functions locally by calling an administration endpoint. Calling this endpoint with an HTTP POST request on the local server triggers the function.
419
+
420
+
To test Event Grid triggered functions locally, see [Local testing with viewer web app](functions-bindings-event-grid-trigger.md#local-testing-with-viewer-web-app).
421
+
422
+
You can optionally pass test data to the execution in the body of the POST request. This functionality is similar to the **Test** tab in the Azure portal.
410
423
411
424
You call the following administrator endpoint to trigger non-HTTP functions:
412
425
@@ -422,16 +435,22 @@ To pass test data to the administrator endpoint of a function, you must supply t
422
435
423
436
The `<trigger_input>` value contains data in a format expected by the function. The following cURL example is a POST to a `QueueTriggerJS` function. In this case, the input is a string that is equivalent to the message expected to be found in the queue.
424
437
438
+
# [Bash](#tab/bash)
439
+
```bash
440
+
curl --request POST -H "Content-Type:application/json" --data '{"input":"sample queue data"}' http://localhost:7071/admin/functions/QueueTrigger
441
+
```
442
+
# [Cmd](#tab/cmd)
425
443
```bash
426
-
curl --request POST -H "Content-Type:application/json" --data '{"input":"sample queue data"}' http://localhost:7071/admin/functions/QueueTriggerJS
444
+
curl --request POST -H "Content-Type:application/json" --data "{'input':'sample queue data'}" http://localhost:7071/admin/functions/QueueTrigger
427
445
```
446
+
---
428
447
429
-
#### Using the `func run` command in version 1.x
448
+
#### Using the `func run` command (version 1.x only)
430
449
431
450
>[!IMPORTANT]
432
-
> The `func run` command is not supported in version 2.x of the tools. For more information, see the topic [How to target Azure Functions runtime versions](set-runtime-version.md).
451
+
> The `func run` command is only supported in version 1.x of the tools. For more information, see the topic [How to target Azure Functions runtime versions](set-runtime-version.md).
433
452
434
-
You can also invoke a function directly by using `func run <FunctionName>` and provide input data for the function. This command is similar to running a function using the **Test** tab in the Azure portal.
453
+
In version 1.x, you can also invoke a function directly by using `func run <FunctionName>` and provide input data for the function. This command is similar to running a function using the **Test** tab in the Azure portal.
435
454
436
455
`func run` supports the following options:
437
456
@@ -445,7 +464,7 @@ You can also invoke a function directly by using `func run <FunctionName>` and p
445
464
446
465
For example, to call an HTTP-triggered function and pass content body, run the following command:
447
466
448
-
```bash
467
+
```
449
468
func run MyHttpTrigger -c '{\"name\": \"Azure\"}'
450
469
```
451
470
@@ -462,7 +481,7 @@ A project folder may contain language-specific files and directories that should
462
481
463
482
To publish your local code to a function app in Azure, use the `publish` command:
464
483
465
-
```bash
484
+
```
466
485
func azure functionapp publish <FunctionAppName>
467
486
```
468
487
@@ -499,7 +518,7 @@ The following publish options are only supported in version 2.x:
499
518
500
519
Azure Functions lets you deploy your function project in a [custom Docker container](functions-deployment-technologies.md#docker-container). For more information, see [Create a function on Linux using a custom image](functions-create-function-linux-custom-image.md). Custom containers must have a Dockerfile. To create an app with a Dockerfile, use the --dockerfile option on `func init`.
0 commit comments