Skip to content

Commit de45849

Browse files
committed
Update Function creation via the CLI
1 parent 0217a9e commit de45849

8 files changed

+29
-21
lines changed

media/007_CLI_New_Function.png

9.67 KB
Loading

media/008_CLI_New_Function.png

2.21 KB
Loading

media/009_CLI_New_Function.png

1.11 KB
Loading

media/010_CLI_New_Function.png

-922 Bytes
Loading

media/012_CLI_New_Function.png

-4.66 KB
Loading

media/013_CLI_New_Function.png

-1.67 KB
Loading

media/017_CLI_New_Function.png

27.3 KB
Loading

readme.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ In this lab, you will learn how to:
3636
![Screen shot 003 - Select a type of function][3]
3737

3838
7. After the Function is created you get to see a dashboard with some code and a couple of buttons. Just press **Run** and see what happens.
39+
3940
8. In the right bottom corner you can see the output result. Obviously you can change the *name* request property in the request body and press *Run* in the bottom right corner to see the changes.
4041
![Screen shote 004 - HTTP Result][4]
42+
4143
9. Now we have a functional 'API' so to speak. We need an URL to send requests to. In the top right corner there is small link **'</> Get function URL'** Click this link to gain the URL.
4244
![Screen shot 005 - API URL][5]
45+
4346
10. You can test this URL by just plain pasting it into the browser and run it. Additionally you can append a 'name' property into the querystring to test the response.
4447
![Screen shot 006 - HTTP Response][6]
4548

@@ -54,58 +57,60 @@ In this lab, you will learn how to:
5457
<a name="create-from-cli"></a>
5558
## Create a function from the Command Line Interface (CLI)
5659

57-
At this moment the *Azure Functions* option (which is available from the Azure SDK) is not yet supported for Visual Studio 2017. The Microsoft Azure team is working hard to get it live but while I'm writing this Lab there is still no release date available. Source: [GitHub Azure](https://github.com/Azure/Azure-Functions/issues/201)
58-
The version for Visual Studio 2015 that IS available is not always working as expected. Actually I couldn't get it to work at all.
59-
Luckily there is a way to create a local Azure Function via the Command Line Interface (CLI).
6060
In this Lab we will create the same Azure Function as before but we don't create it in the cloud via a fancy portal. We want to create it locally before sending it to Azure.
6161
This is convenient because this way we can develop and test the function without any Azure costs (as we are using our localhost IIS as 'provider')
6262

6363
1. First of, make sure you have Node Package Manager (NPM) installed. See [npmjs.org/get-npm](https://www.npmjs.com/get-npm) for more information.
64-
2. Next, open the command prompt (you can use the nodejs command prompt or the default DOS prompt) and install the *azure-functions-cli* package globally:
64+
65+
2. Next, open the command prompt as administrator (you can use the nodejs command prompt or the default DOS prompt) navigate to a desired empty folder and install the *azure-functions-core-tools* package globally:
6566
```code
66-
npm install -g azure-functions-cli
67+
npm install -g azure-functions-core-tools
6768
```
6869
69-
Which results in npm downloading and installing the Azure Functions CLI package into the current directory.
70+
Which results in npm downloading and installing the _Azure Functions CLI_ package into the current directory.
7071
![Screenshot 007 install Azure Functions CLI via NPM][7]
7172
7273
3. Meanwhile create a new folder on a location where you desire to create a new local Azure Function.
74+
7375
4. When the installation is done navigate via the prompt to the directory you just created.
76+
7477
5. Run *func* as a command to the see possible options.
7578
![Screenshot 008 Create a new Azure Function via the CLI][8]
7679
7780
6. We want to create a new Azure Function so let's run the following commmand:
7881
```code
7982
func new
8083
```
84+
8185
7. It will return a list of language options. Use the **UP** and **DOWN** key to scroll trough the possible options and select **C#** by pressing *Enter*.
82-
![Screenshot 009 A new function based on C#][9]
86+
87+
![Screenshot 009 A new function based on C#][9]
8388
8489
> Tip: Hit CTRL+C to abort the current execution (for instance when you picked the wrong template)
8590
8691
8. Next select the **HttpTrigger** option from the template list.
8792
9. Finally type a name of your Azure Function and press enter to start the creation of the Function. Please be aware that the name you enter here will be created as a folder so try to prevent spaces and other non-folderish-names and keep it short.
8893
![Screenshot 010 Naming the Azure function][10]
8994
90-
>```<nerd-modus>```
91-
>
92-
> You can also go complete rogue and type the whole command at once by using the following parameters:
93-
>
94-
> ```func new -l C# -t HttpTrigger -n AzureBootcampLocal```
95-
>
96-
>```</nerd-modus>```
95+
\
96+
```<nerd-modus>```
97+
98+
You can also go rogue and type the whole command at once by using the following parameters:
9799
98-
![Screenshot 011 Be that nerd!][11]
100+
> func new -l C# -t HttpTrigger -n AzureBootcampLocal
101+
![Screenshot 011 Be that nerd!][11]
102+
103+
```</nerd-modus>```
99104
100105
101106
10. Now when you check out the directory you can see that a new folder was created, with the name you've just entered and a foursome of files. You can open run.csx and check out the code. That might look a bit familiar. That's because it's the same default template as we created in the online portal.
102-
11. Tryin to run this Azure Function with ```func run AzureBootcampLocal``` followed by an extra enter (confirming the launch of a new server) leads to an unforgiving and not-so-very-explanatory exception: **An error occurred while sending the request**
107+
11. Tryin to run this Azure Function with ```func run AzureBootcampLocal``` followed by an extra enter (confirming the launch of a new server) leads to an unforgiving and not-so-very-explanatory exception: **Unable to find function project root. Expecting to have host.json in function project root.**
103108
![Screenshot 012 Wut?!][12]
104109
105-
12. Before you can run the function you need to initialize it first. You can do so by running the next command: ```func init``` (nb. without the name of the project)
106-
> Tip: Running ```func init AzureBootcampLocal``` will not work. The files end up in the wrong folder and the server wont start giving you the same exception as earlier 'An error occurred while sending the request'.
110+
12. Before you can run the function you need to initialize it first. You can do so by running the next command: ```func init```
111+
107112
108-
13. After that you can run ```func run AzureBootcampLocal``` again to start up the local server and run your Function. This will open a new Command window showing the host information like below:
113+
13. After that you can run ```func run AzureBootcampLocal``` again to start up the local server and run your Function. Hit enter when the question appears of always showing a warning. This will open a new Command window showing the host information like below:
109114
110115
![Screenshot 013 Localhost][13]
111116
@@ -120,9 +125,11 @@ This will show up a page confirming that the server is operating and the functio
120125
16. So append the requested parameter to the URI string and run request again.
121126
![Screenshot 016 Localhost][16]
122127
123-
> You can also use Postman instead of your browser but I just wanted to show the working function.
128+
> You can also use Postman instead of your browser.
129+
![Screenshot 017 Request via Postman][17]
130+
124131
125-
17. There you have it (again), A fully functional Azure Function but local so you can test it first.
132+
17. There you have it (again), A fully functional Azure Function, but local so you can test it first.
126133
127134
128135
@@ -147,3 +154,4 @@ For more information, please check out [functions.azure.com](https://functions.a
147154
[14]: media/014_CLI_New_Function.png
148155
[15]: media/015_CLI_New_Function.png
149156
[16]: media/016_CLI_New_Function.png
157+
[17]: media/017_CLI_New_Function.png

0 commit comments

Comments
 (0)