Skip to content

Commit 007fe16

Browse files
Merge pull request #261373 from ggailey777/patch-2
[Functions] Updates for Node.js and Python CLI quickstarts
2 parents efc3f97 + 641e781 commit 007fe16

File tree

3 files changed

+34
-89
lines changed

3 files changed

+34
-89
lines changed

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

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create a JavaScript function from the command line - Azure Functions
33
description: Learn how to create a JavaScript function from the command line, then publish the local Node.js project to serverless hosting in Azure Functions.
4-
ms.date: 03/08/2023
4+
ms.date: 12/15/2023
55
ms.topic: quickstart
66
ms.devlang: javascript
77
ms.custom: devx-track-azurecli, devx-track-azurepowershell, mode-api, devx-track-js
@@ -49,27 +49,20 @@ Before you begin, you must have the following prerequisites:
4949
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. In this section, you create a function project that contains a single function.
5050

5151
::: zone pivot="nodejs-model-v3"
52-
1. Run the `func init` command, as follows, to create a functions project in a folder named *LocalFunctionProj* with the specified runtime:
52+
1. In a suitable folder, run the [`func init`](functions-core-tools-reference.md#func-init) command, as follows, to create a JavaScript Node.js v3 project in the current folder:
5353

5454
```console
55-
func init LocalFunctionProj --javascript
55+
func init --javascript --model V3
5656
```
57-
58-
1. Navigate into the project folder:
59-
60-
```console
61-
cd LocalFunctionProj
62-
```
63-
64-
This folder contains various files for the project, including configurations 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.
57+
This folder now contains various files for the project, including configurations 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.
6558

6659
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).
6760

6861
```console
6962
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
7063
```
7164

72-
`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*.
65+
[`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*.
7366

7467
You may find the [Azure Functions Core Tools reference](functions-core-tools-reference.md) helpful.
7568

@@ -96,30 +89,20 @@ Each binding requires a direction, a type, and a unique name. The HTTP trigger h
9689
::: zone-end
9790

9891
::: zone pivot="nodejs-model-v4"
99-
1. Run the `func init` command, as follows, to create a functions project in a folder named *LocalFunctionProj*:
100-
101-
```console
102-
func init LocalFunctionProj --model V4
103-
```
104-
You're then prompted to choose a worker runtime and a language - choose Node for the first and JavaScript for the second.
105-
106-
2. Navigate into the project folder:
92+
1. In a suitable folder, run the [`func init`](functions-core-tools-reference.md#func-init) command, as follows, to create a JavaScript Node.js v4 project in the current folder:
10793

10894
```console
109-
cd LocalFunctionProj
95+
func init --javascript
11096
```
11197

112-
This folder contains various files for the project, including configurations files named *local.settings.json* and *host.json*. Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file.
98+
This folder now contains various files for the project, including configurations files named *local.settings.json* and *host.json*. Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file. Required npm packages are also installed in *node_modules*.
11399

114-
3. Add a function to your project by using the following command:
100+
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).
115101

116102
```console
117-
func new
118-
```
119-
120-
Choose the template for "HTTP trigger". You can keep the default name (*httpTrigger*) or give it a new name (*HttpExample*). Your function name must be unique, or you're asked to confirm if your intention is to replace an existing function.
103+
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
121104

122-
You can find the function you added in the *src/functions* directory.
105+
[`func new`](functions-core-tools-reference.md#func-new) creates a file named *HttpExample.js* in the *src/functions* directory, which contains your function's code.
123106

124107
4. Add Azure Storage connection information in *local.settings.json*.
125108
```json

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

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ In Azure Functions, a function project is a container for one or more individual
9191
::: zone pivot="python-mode-configuration"
9292
In this section, you create a function project that contains a single function.
9393

94-
1. Run the `func init` command as follows to create a Python functions project in the virtual environment.
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.
9595

9696
```console
97-
func init --python
97+
func init --python --model V1
9898
```
9999

100100
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.
@@ -105,7 +105,7 @@ In this section, you create a function project that contains a single function.
105105
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
106106
```
107107

108-
`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*.
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*.
109109

110110
1. Run this command to make sure that the Azure Functions library is installed in the environment.
111111

@@ -133,43 +133,21 @@ In this section, you create a function project that contains a single function.
133133
::: zone pivot="python-mode-decorators"
134134
In this section, you create a function project and add an HTTP triggered function.
135135

136-
1. Run the `func init` command as follows to create a Python v2 functions project in the virtual environment.
136+
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.
137137

138138
```console
139-
func init --python -m V2
139+
func init --python
140140
```
141141

142142
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.
143143

144-
1. The file `function_app.py` can include all functions within your project. Open this file and replace the existing contents with the following code that defines an HTTP triggered function endpoint named `HttpExample`:
144+
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).
145145

146-
```python
147-
import azure.functions as func
148-
import logging
149-
150-
app = func.FunctionApp()
151-
152-
@app.route(route="HttpExample", auth_level=func.AuthLevel.ANONYMOUS)
153-
def test_function(req: func.HttpRequest) -> func.HttpResponse:
154-
logging.info('Python HTTP trigger function processed a request.')
155-
156-
name = req.params.get('name')
157-
if not name:
158-
try:
159-
req_body = req.get_json()
160-
except ValueError:
161-
pass
162-
else:
163-
name = req_body.get('name')
164-
165-
if name:
166-
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
167-
else:
168-
return func.HttpResponse(
169-
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
170-
status_code=200
171-
)
146+
```console
147+
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
172148
```
149+
150+
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.
173151
174152
1. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This is required for Functions to interpret your project correctly as the Python v2 model. You'll add this same setting to your application settings after you publish your project to Azure.
175153

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

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create a TypeScript function from the command line - Azure Functions
33
description: Learn how to create a TypeScript function from the command line, then publish the local project to serverless hosting in Azure Functions.
4-
ms.date: 03/06/2023
4+
ms.date: 12/15/2023
55
ms.topic: quickstart
66
ms.devlang: typescript
77
ms.custom: devx-track-azurecli, devx-track-azurepowershell, mode-other, devx-track-js
@@ -50,27 +50,21 @@ Before you begin, you must have the following prerequisites:
5050
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. In this section, you create a function project that contains a single function.
5151

5252
::: zone pivot="nodejs-model-v3"
53-
1. Run the `func init` command, as follows, to create a functions project in a folder named *LocalFunctionProj* with the specified runtime:
53+
1. In a suitable folder, run the [`func init`](functions-core-tools-reference.md#func-init) command, as follows, to create a TypeScript Node.js v3 project in the current folder:
5454

5555
```console
56-
func init LocalFunctionProj --typescript
56+
func init --typescript --model V3
5757
```
58+
59+
This folder now contains various files for the project, including configurations 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.
5860

59-
2. Navigate into the project folder:
60-
61-
```console
62-
cd LocalFunctionProj
63-
```
64-
65-
This folder contains various files for the project, including configurations 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.
66-
67-
3. 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).
61+
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).
6862

6963
```console
7064
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
7165
```
7266

73-
`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*.
67+
[`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*.
7468

7569
### (Optional) Examine the file contents
7670

@@ -95,31 +89,21 @@ Each binding requires a direction, a type, and a unique name. The HTTP trigger h
9589
::: zone-end
9690

9791
::: zone pivot="nodejs-model-v4"
98-
1. Run the `func init` command, as follows, to create a functions project in a folder named *LocalFunctionProj* with the V4 programming model:
92+
1. In a suitable folder, run the [`func init`](functions-core-tools-reference.md#func-init) command, as follows, to create a TypeScript Node.js v4 project in the current folder:
9993

10094
```console
101-
func init LocalFunctionProj --model V4
95+
func init --typescript
10296
```
10397

104-
You're then prompted to choose a worker runtime and a language - choose Node for the first and TypeScript for the second.
98+
This folder now contains various files for the project, including configurations files named *local.settings.json* and *host.json*. Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file. Required npm packages are also installed in *node_modules*.
10599

106-
2. Navigate into the project folder:
100+
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).
107101

108102
```console
109-
cd LocalFunctionProj
110-
```
111-
112-
This folder contains various files for the project, including configurations files named *local.settings.json* and *host.json*. Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file.
113-
114-
3. Add a function to your project by using the following command:
115-
116-
```console
117-
func new
103+
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
118104
```
119105

120-
Choose the template for "HTTP trigger". You can keep the default name (*httpTrigger*) or give it a new name (*HttpExample*). Your function name must be unique, or you're asked to confirm if your intention is to replace an existing function.
121-
122-
You can find the function you added in the *src/functions* directory.
106+
[`func new`](functions-core-tools-reference.md#func-new) creates a file named *HttpExample.ts* in the *src/functions* directory, which contains your function's code.
123107

124108
4. Add Azure Storage connection information in *local.settings.json*.
125109
```json

0 commit comments

Comments
 (0)