A Website without Servers – Using Azure Functions Part 3
In part 2 of this series, we learned how to set up source control for an Azure Function project. Now we are going to learn how to do it a better way, and probably the way you want to do it.
Previously, we learned how to link a VSO source control location project with our Azure Functions application. Now we are going to develop an Azure Function application in Visual Studio, like we would any other application. Creating this application in VS gives us three benefits:
- Allows us to disconnect our source control from our hosting. In general, it is nice to have a little buffer between source and hosting.
- Allows us to do all development locally.
- Allows us to set up ourselves for solid unit testing without doing anything too weird.
Start by installing the Azure Functions extension. Go to Tools -> Extensions and Updates. From there, install the “Azure Functions and Web Jobs Tools” extension.
Create a new Azure Functions project.
Create a new Function by right-clicking on Project and select Add -> New Item.
That will give us a new Azure Function app, and we can run it in VS! Just press the green play button to give it a try.
This should pop up a console window, which will tell you what port the application is running on.
You can then test the application on that port, with something like this:
https://localhost:7071/api/Test1?name=bob
That should give you a response like this:
Now let’s deploy our Azure Function application. Create a Function app in the Azure Portal.
Then we need to download the publishing profile.
After downloading the profile, go back into Visual Studio. Right-click on the project and select “Publish”. A screen will pop up and click “Import”. Select the publishing profile downloaded earlier.
After importing it you will be able to publish you Azure Function to Azure with just the click of a button.
And since we are not connected directly to Azure Functions with our source, we can easily push our source into VSO just like we would any normal project.