I blogged about Azure Functions before. It is one of the incarnations of FaaS(Functions as a Service), comparable to AWS Lambda on the Amazon Cloud stack. But Microsoft wouldn’t be Microsoft if they didn’t had plans to improve the development experience. And yes, now we have (a first preview of )Visual Studio Tools for Azure Functions.
After downloading the preview, you get the ability to create a function project in Visual Studio, run and test them locally and publish them to Azure.
- Once you have the tools installed, you can open Visual Studio and choose the Azure Functions project template. Click OK.
- Inside the created project, you’ll find 2 important files
- appsettings.json: this file is used to store configuration data for the azure function
- host.json: contains the global configuration options affecting all functions(more info at https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json)
- Next step is to add one or more azure functions to our project. Right click on the project. Choose Add –> New Azure Function…
- The New Azure Function window is loaded. Choose a template.
- As a an example I take the HttpTrigger-Batch, specify a random name and click Create.
- A new folder is created containing following files:
- function.json: contains the configuration data of the function(more info at https://github.com/Azure/azure-webjobs-sdk-script/wiki/function.json)
- run.bat: the batch script that gets invoked when the HttpTrigger is activated
- Let’s try the sample by hitting F5. The first time you try to run/debug an Azure function locally you get a confirmation prompt to download and install the Azure Functions CLI tools.
- Once the Azure function is started, I can invoke it by calling the specified endpoint(in this sample http://localhost:7071/api/HttpTriggerBatchSample).
- I enter the following URL in the browser: http://localhost:7071/api/HttpTriggerBatchSample?name=%22test%22 and I can see that my batch job is indeed invoked.