This walk-through shows how to use Visual Studio to create and run an Azure Functions project.
The sample project includes two different types of Azure Functions and demonstrates:
- how to trigger a function when an item shows up in a Queue (using a Queue Trigger)
- how to trigger a function when a user posts an HTTP request (using an HTTP Trigger)
- how to configure a local storage queue for testing (using Windows Storage Emulator)
- how to locally debug an Azure Function
The major steps in the tutorial are:
- Setup Functions Project inside Visual Studio
- Setup Queue (for Queue Trigger)
- Test/Debug the Queue Trigger (Locally)
- Test the Http Trigger (Locally)
- Clone source from GitHub: https://github.com/justcla/AzureFunctionsDemo
- File -> New -> Project
- Visual C# -> Cloud -> Azure Functions
- Name: "AzureFunctionsDemo"
- Visual C# -> Cloud -> Azure Functions
- Project -> Add New Item…
- Visual C# Items -> Azure Function
- Name: "HttpTriggerFunction.cs"
- Visual C# Items -> Azure Function
- Project -> Add New Item…
- Visual C# Items -> Azure Function
- Name: "QueueTriggerFunction.cs"
- Connection: "AzureWebJobsStorage"
- Visual C# Items -> Azure Function
- Update local.settings.json
- "AzureWebJobsStorage": "UseDevelopmentStorage=true"
-
Start Azure Storage Emulator
-
Open Cloud Explorer in Visual Studio
- View->Cloud Explorer
-
Add queue to local storage account
-
Use the "Add Message" icon - 3rd from the right on queue toolbar
-
Enter text into message box: "Test message 1"
Message appears in queue explorer window in Visual Studio
-
Debug -> Step Over (F10)
New messages printed in Functions Terminal Window
Note: "Test message 1" appears printed on the console. -
Debug -> Continue (F5)
Execution completes. -
Debug -> Stop Debugging (Shift+F5)
-
Debug -> Start Debugging (F5)
Functions Terminal Window will start
-
Note the URL of the Http Function (HttpTriggerFunction) printed in the terminal window.
Eg. http://localhost:7071/api/HttpTriggerFunction -
Open a web browser and enter the Http Function URL
Program runs and asks for a "name" parameter. -
Append name parameter to URL query string
Eg. http://localhost:7071/api/HttpTriggerFunction?name=Harry
Program runs and outputs: "Hello Harry" -
Debug -> Stop Debugging (Shift+F5)