June 8, 2021
Create Your Free Azure and Cosmos DB Account
Azure Functions is a serverless solution to run code in the cloud. The functions run inside a function app. You can develop functions directly in the Azure portal, or use VS Code or Visual Studio.
I see the functions as a way to write small portions of code reacting to external events. These events are called triggers and can be different types, like HTTP traffic, changes made in blob storage, database changes, timers, etc.
The function can also use input and output parameters in the definition or use dependency injection, and then return a response or do other complex work as add a document to a Cosmos DB database.
In this short demo, I will show you how to create a new function and run it locally in Visual Studio and then publish it to Azure.
We start with a new project in Visual Studio 2019 for Azure Functions
And then set our project location
Now we must specify a few details for our new app. I will select the HTTP trigger to see how functions can reply to HTTP calls, and for now, I’ll set the authorization as Anonymous and the Storage account as None
After a moment we can see our new project in Visual Studio and a new basic function to be used as a template.
Every function is created as a static class with a Run method that is called when the function is executed, in this case, as a result of an HTTP call.
If we start the project we can see:
To publish, we can use the publish wizard, which available in the context menu for our project in the Solution Explorer, and then select Azure.
We will use an existing Azure subscription to create a new Linux-based or Windows-based function app and to configure the location and other plan-related information. I will selected a Linux-based fuction app.
After the creation of our function app, we will see a dialog with information about our function app such as its base endpoint.
Using the Publish button, the function will be publicly available.
In the Azure portal we can access our function, run it from there or see metrics and a log of the current calls.
From here, you can check the official documentation to learn more about this interesting technology.
Thanks for reading and see you soon!