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
## <aname="create-an-azure-functions-project"></a>Create your local project
38
+
39
+
In this section, you use Visual Studio Code to create a local Azure Functions project.
40
+
41
+
1. In Visual Studio Code, press F1 to open the command palette. In the command palette, search for and select `Azure Functions: Create new project...`.
42
+
43
+
1. Choose a directory location for your project workspace and choose **Select**.
44
+
45
+
> [!NOTE]
46
+
> These steps were designed to be completed outside of a workspace. In this case, do not select a project folder that is part of a workspace.
47
+
48
+
1. Following the prompts, provide the following information for your desired language:
49
+
50
+
| Prompt | Value | Description |
51
+
| ------ | ----- | ----------- |
52
+
| Select a language for your function app project | JavaScript | Create a local Node.js Functions project. |
53
+
| Select a version | Azure Functions v2 | You only see this option when the Core Tools aren't already installed. In this case, Core Tools are installed the first time you run the app. |
54
+
| Select a template for your project's first function | HTTP trigger | Create an HTTP triggered function in the new function app. |
55
+
| Provide a function name | HttpTrigger | Press Enter to use the default name. |
56
+
| Authorization level | Function | The `function` authorization level requires you to supply an access key when calling your function's HTTP endpoint. This makes it more difficult to access an unsecured endpoint. To learn more, see [Authorization keys](../functions-bindings-http-webhook.md#authorization-keys). |
57
+
| Select how you would like to open your project | Add to workspace | Creates the function app in the current workspace. |
58
+
59
+
Visual Studio Code installs the Azure Functions Core Tools, if needed. It also creates a function app project in a new workspace. This project contains the [host.json](../functions-host-json.md) and [local.settings.json](../functions-run-local.md#local-settings-file) configuration files. It also creates an HttpExample folder that contains the [function.json definition file](../functions-reference-node.md#folder-structure) and the [index.js file](../functions-reference-node.md#exporting-a-function), a Node.js file that contains the function code.
60
+
61
+
A package.json file is also created in the root folder.
# Connect functions to Azure Storage using Visual Studio Code
@@ -19,8 +20,13 @@ Most bindings require a stored connection string that Functions uses to access t
19
20
Before you start this article, you must meet the following requirements:
20
21
21
22
* Install the [Azure Storage extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestorage).
23
+
22
24
* Install [Azure Storage Explorer](https://storageexplorer.com/). Storage Explorer is a tool you'll use to examine queue messages generated by your output binding. Storage Explorer is supported on macOS, Windows, and Linux-based operating systems.
* Complete the steps in [part 1 of the Visual Studio Code quickstart](functions-create-first-function-vs-code.md).
25
31
26
32
This article assumes that you are already signed in to your Azure subscription from Visual Studio Code. You can sign in by running `Azure: Sign In` from the command palette.
@@ -42,50 +48,163 @@ In the [previous quickstart article](functions-create-first-function-vs-code.md)
42
48
43
49
Because you are using a Queue storage output binding, you must have the Storage bindings extension installed before you run the project.
44
50
45
-
# [JavaScript](#tab/nodejs)
51
+
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-powershell"
With the exception of HTTP and timer triggers, bindings are implemented as extension packages. Run the following [dotnet add package](/dotnet/core/tools/dotnet-add-package) command in the Terminal window to add the Storage extension package to your project.
Now, you can add the storage output binding to your project.
58
68
59
69
## Add an output binding
60
70
61
71
In Functions, each type of binding requires a `direction`, `type`, and a unique `name` to be defined in the function.json file. The way you define these attributes depends on the language of your function app.
62
72
63
-
# [JavaScript](#tab/nodejs)
73
+
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-powershell"
After the binding is defined, you can use the `name` of the binding to access it as an attribute in the function signature. By using an output binding, you don't have to use the Azure Storage SDK code for authentication, getting a queue reference, or writing data. The Functions runtime and queue output binding do those tasks for you.
context.bindings.msg="Name passed to the function: "+ name;
116
+
// Send a "hello" response.
117
+
context.res= {
118
+
// status: 200, /* Defaults to 200 */
119
+
body:"Hello "+ (req.query.name||req.body.name)
120
+
};
121
+
}
122
+
else {
123
+
context.res= {
124
+
status:400,
125
+
body:"Please pass a name on the query string or in the request body"
126
+
};
127
+
}
128
+
};
129
+
130
+
exportdefaulthttpTrigger;
131
+
```
132
+
133
+
::: zone-end
134
+
135
+
::: zone pivot="programming-language-powershell"
136
+
137
+
Add code that uses the `Push-OutputBinding` cmdlet to write text to the queue using the `msg` output binding. Add this code before you set the OK status in the `if` statement.
138
+
139
+
```powershell
140
+
# Write the $name value to the queue.
141
+
$outputMsg = "Name passed to the function: $name"
142
+
Push-OutputBinding -name msg -Value $outputMsg
143
+
```
144
+
145
+
At this point, your function should look as follows:
146
+
147
+
```powershell
148
+
using namespace System.Net
149
+
150
+
# Input bindings are passed in via param block.
151
+
param($Request, $TriggerMetadata)
152
+
153
+
# Write to the Azure Functions log stream.
154
+
Write-Host "PowerShell HTTP trigger function processed a request."
155
+
156
+
# Interact with query parameters or the body of the request.
157
+
$name = $Request.Query.Name
158
+
if (-not $name) {
159
+
$name = $Request.Body.Name
160
+
}
161
+
162
+
if ($name) {
163
+
# Write the $name value to the queue.
164
+
$outputMsg = "Name passed to the function: $name"
165
+
Push-OutputBinding -name msg -Value $outputMsg
166
+
167
+
$status = [HttpStatusCode]::OK
168
+
$body = "Hello $name"
169
+
}
170
+
else {
171
+
$status = [HttpStatusCode]::BadRequest
172
+
$body = "Please pass a name on the query string or in the request body."
173
+
}
174
+
175
+
# Associate values to output bindings by calling 'Push-OutputBinding'.
A new queue named **outqueue** is created in your storage account by the Functions runtime when the output binding is first used. You'll use Storage Explorer to verify that the queue was created along with the new message.
90
209
91
210
### Connect Storage Explorer to your account
@@ -136,27 +255,13 @@ Now, it's time to republish the updated function app to Azure.
136
255
137
256
You created resources to complete these quickstarts. You may be billed for these resources, depending on your [account status](https://azure.microsoft.com/account/) and [service pricing](https://azure.microsoft.com/pricing/). If you don't need the resources anymore, here's how to delete them:
138
257
139
-
1. In Visual Studio Code, press F1 to open the command palette. In the command palette, search forand select `Azure Functions: Openin portal`.
140
-
141
-
1. Choose your functionapp, and press Enter. The functionapp page is opened in the [Azure portal](https://portal.azure.com).
142
-
143
-
1. In the **Overview** tab, selectthe named link under **Resource group**.
144
-
145
-

146
-
147
-
1. In the **Resource group** page, review the list of included resources, and verify that they are the ones you want to delete.
148
-
149
-
1. Select **Delete resource group**, and follow the instructions.
150
-
151
-
Deletion may take a couple of minutes. When it's done, a notification appears for a few seconds. You can also select the bell icon at the top of the page to view the notification.
You've updated your HTTP triggered functionto write data to a Storage queue. To learn more about developing Functions, see [Develop Azure Functions using Visual Studio Code](functions-develop-vs-code.md).
156
-
157
-
Next, you should enable Application Insights monitoring for your functionapp:
262
+
You've updated your HTTP triggered function to write data to a Storage queue. Next, you can learn more about developing Functions using Visual Studio Code:
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-create-first-function-powershell.md
+1-30Lines changed: 1 addition & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,36 +62,7 @@ The Azure Functions project template in Visual Studio Code creates a project tha
62
62
63
63
Visual Studio Code creates the PowerShell function app project in a new workspace. This project contains the [host.json](functions-host-json.md) and [local.settings.json](functions-run-local.md#local-settings-file) configuration files, which apply to all function in the project. This [PowerShell project](functions-reference-powershell.md#folder-structure) is the same as a function app running in Azure.
64
64
65
-
## Run the function locally
66
-
67
-
Azure Functions Core Tools integrates with Visual Studio Code to let you run and debug an Azure Functions project locally.
68
-
69
-
1. To debug your function, insert a call to the [`Wait-Debugger`] cmdlet in the function code before you want to attach the debugger, then press F5 to start the function app project and attach the debugger. Output from Core Tools is displayed in the **Terminal** panel.
70
-
71
-
1. In the **Terminal** panel, copy the URL endpoint of your HTTP-triggered function.
72
-
73
-

74
-
75
-
1. Append the query string `?name=<yourname>` to this URL, and then use `Invoke-RestMethod` to execute the request, as follows:
76
-
77
-
```powershell
78
-
PS > Invoke-RestMethod -Method Get -Uri http://localhost:7071/api/HttpTrigger?name=PowerShell
79
-
Hello PowerShell
80
-
```
81
-
82
-
You can also execute the GET request from a browser.
83
-
84
-
When you call the HttpTrigger endpoint without passing a `name` parameter either as a query parameter or in the body, the function returns a [HttpStatusCode]::BadRequest error. When you review the code in run.ps1, you see that this error occurs by design.
85
-
86
-
1. To stop debugging, press Shift + F5.
87
-
88
-
After you've verified that the function runs correctly on your local computer, it's time to publish the project to Azure.
89
-
90
-
> [!NOTE]
91
-
> Remember to remove any calls to `Wait-Debugger` before you publish your functions to Azure.
92
-
>
93
-
> Creating a function app in Azure only prompts for your function app name. Other values are defined for you.
94
-
> Set `azureFunctions.advancedCreation` to `true` to be prompted for all other values.
0 commit comments