Skip to content

Commit 9bf8dac

Browse files
authored
Merge pull request #106433 from ggailey777/patch-4
Event grid test local link and commands clean-up
2 parents a3a7d51 + fd791da commit 9bf8dac

File tree

1 file changed

+69
-50
lines changed

1 file changed

+69
-50
lines changed

articles/azure-functions/functions-run-local.md

Lines changed: 69 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ The following steps use npm to install Core Tools on Windows. You can also use [
6060

6161
##### v2.x
6262

63-
```bash
63+
```cmd
6464
npm install -g azure-functions-core-tools
6565
```
6666
6767
##### v3.x
6868
69-
```bash
69+
```cmd
7070
npm install -g azure-functions-core-tools@3
7171
```
7272
7373
It may take a few minutes for npm to download and install the Core Tools package.
7474
7575
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).
7676
77-
# [MacOS](#tab/macos)
77+
# [macOS](#tab/macos)
7878
7979
The following steps use Homebrew to install the Core Tools on macOS.
8080
@@ -158,33 +158,33 @@ Version 2.x requires you to select a default language for your project when it i
158158
159159
In the terminal window or from a command prompt, run the following command to create the project and local Git repository:
160160
161-
```bash
161+
```
162162
func init MyFunctionProj
163163
```
164164
165165
When you provide a project name, a new folder with that name is created and initialized. Otherwise, the current folder is initialized.
166166
In version 2.x, when you run the command you must choose a runtime for your project.
167167
168-
```output
168+
<pre>
169169
Select a worker runtime:
170170
dotnet
171171
node
172172
python
173173
powershell
174-
```
174+
</pre>
175175
176176
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).
177177
178178
The output looks like the following example for a JavaScript project:
179179
180-
```output
180+
<pre>
181181
Select a worker runtime: node
182182
Writing .gitignore
183183
Writing host.json
184184
Writing local.settings.json
185185
Writing C:\myfunctions\myMyFunctionProj\.vscode\extensions.json
186186
Initialized empty Git repository in C:/myfunctions/myMyFunctionProj/.git/
187-
```
187+
</pre>
188188
189189
`func init` supports the following options, which are version 2.x-only, unless otherwise noted:
190190
@@ -242,12 +242,12 @@ Even when using the Microsoft Azure Storage Emulator for development, you may wa
242242
243243
+ Download all settings from an existing function app:
244244
245-
```bash
245+
```
246246
func azure functionapp fetch-app-settings <FunctionAppName>
247247
```
248248
+ Get the Connection string for a specific storage account:
249249
250-
```bash
250+
```
251251
func azure storage fetch-connection-string <StorageAccountName>
252252
```
253253
@@ -257,13 +257,13 @@ Even when using the Microsoft Azure Storage Emulator for development, you may wa
257257
258258
To create a function, run the following command:
259259
260-
```bash
260+
```
261261
func new
262262
```
263263
264264
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.
265265
266-
```output
266+
<pre>
267267
Select a language: Select a template:
268268
Blob trigger
269269
Cosmos DB trigger
@@ -274,18 +274,18 @@ SendGrid
274274
Service Bus Queue trigger
275275
Service Bus Topic trigger
276276
Timer trigger
277-
```
277+
</pre>
278278
279279
Function code is generated in a subfolder with the provided function name, as you can see in the following queue trigger output:
280280
281-
```output
281+
<pre>
282282
Select a language: Select a template: Queue trigger
283283
Function name: [QueueTriggerJS] MyQueueTrigger
284284
Writing C:\myfunctions\myMyFunctionProj\MyQueueTrigger\index.js
285285
Writing C:\myfunctions\myMyFunctionProj\MyQueueTrigger\readme.md
286286
Writing C:\myfunctions\myMyFunctionProj\MyQueueTrigger\sample.dat
287287
Writing C:\myfunctions\myMyFunctionProj\MyQueueTrigger\function.json
288-
```
288+
</pre>
289289
290290
You can also specify these options in the command using the following arguments:
291291
@@ -298,62 +298,65 @@ You can also specify these options in the command using the following arguments:
298298
299299
For example, to create a JavaScript HTTP trigger in a single command, run:
300300
301-
```bash
301+
```
302302
func new --template "Http Trigger" --name MyHttpTrigger
303303
```
304304
305305
To create a queue-triggered function in a single command, run:
306306
307-
```bash
307+
```
308308
func new --template "Queue Trigger" --name QueueTriggerJS
309309
```
310310
311311
## <a name="start"></a>Run functions locally
312312
313-
To run a Functions project, run the Functions host. The host enables triggers for all functions in 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.
314314
315-
### Version 2.x
315+
# [C\#](#tab/csharp)
316316
317-
In version 2.x of the runtime, the start command varies, depending on your project language.
318-
319-
#### C\#
320-
321-
```command
317+
```
322318
func start --build
323319
```
320+
# [JavaScript](#tab/node)
321+
322+
```
323+
func start
324+
```
324325
325-
#### JavaScript
326+
# [Python](#tab/python)
326327
327-
```command
328+
```
328329
func start
329330
```
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).
330332
331-
#### TypeScript
333+
# [TypeScript](#tab/ts)
332334
333-
```command
335+
```
334336
npm install
335337
npm start
336338
```
337339
338-
### Version 1.x
339-
340-
Version 1.x of the Functions runtime requires the `host` command, as in the following example:
340+
---
341341
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:
344+
>
345+
> ```
346+
> func host start
347+
> ```
345348
346349
`func start` supports the following options:
347350
348351
| Option | Description |
349352
| ------------ | -------------------------------------- |
350-
| **`--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. |
353356
| **`--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. |
355358
| **`--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. |
357360
| **`--port`**, **`-p`** | The local port to listen on. Default value: 7071. |
358361
| **`--pause-on-error`** | Pause for additional input before exiting the process. Used only when launching Core Tools from an integrated development environment (IDE).|
359362
| **`--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
362365
363366
When the Functions host starts, it outputs the URL of HTTP-triggered functions:
364367
365-
```output
368+
<pre>
366369
Found the following functions:
367370
Host.Functions.MyHttpTrigger
368371
369372
Job host started
370373
Http Function MyHttpTrigger: http://localhost:7071/api/MyHttpTrigger
371-
```
374+
</pre>
372375
373376
>[!IMPORTANT]
374377
>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
392395
393396
The following cURL command triggers the `MyHttpTrigger` quickstart function from a GET request with the _name_ parameter passed in the query string.
394397
395-
```bash
398+
```
396399
curl --get http://localhost:7071/api/MyHttpTrigger?name=Azure%20Rocks
397400
```
398401
399402
The following example is the same function called from a POST request passing _name_ in the request body:
400403
404+
# [Bash](#tab/bash)
401405
```bash
402406
curl --request POST http://localhost:7071/api/MyHttpTrigger --data '{"name":"Azure Rocks"}'
403407
```
408+
# [Cmd](#tab/cmd)
409+
```cmd
410+
curl --request POST http://localhost:7071/api/MyHttpTrigger --data "{'name':'Azure Rocks'}"
411+
```
412+
---
404413

405414
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.
406415

407416
#### Non-HTTP triggered functions
408417

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

411424
You call the following administrator endpoint to trigger non-HTTP functions:
412425

@@ -422,16 +435,22 @@ To pass test data to the administrator endpoint of a function, you must supply t
422435

423436
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.
424437

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)
425443
```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
427445
```
446+
---
428447

429-
#### Using the `func run` command in version 1.x
448+
#### Using the `func run` command (version 1.x only)
430449

431450
>[!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).
433452
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.
435454

436455
`func run` supports the following options:
437456

@@ -445,7 +464,7 @@ You can also invoke a function directly by using `func run <FunctionName>` and p
445464

446465
For example, to call an HTTP-triggered function and pass content body, run the following command:
447466

448-
```bash
467+
```
449468
func run MyHttpTrigger -c '{\"name\": \"Azure\"}'
450469
```
451470

@@ -462,7 +481,7 @@ A project folder may contain language-specific files and directories that should
462481

463482
To publish your local code to a function app in Azure, use the `publish` command:
464483

465-
```bash
484+
```
466485
func azure functionapp publish <FunctionAppName>
467486
```
468487

@@ -499,7 +518,7 @@ The following publish options are only supported in version 2.x:
499518

500519
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`.
501520

502-
```bash
521+
```
503522
func deploy
504523
```
505524

0 commit comments

Comments
 (0)