Skip to content

mohitchhabra/AzureFunctionAIARM

Repository files navigation

Azure Functions & ARM

This project demonstrates Azure Function (v2) and automatic deployment using Azure ARM Templates. The demonstrated functionality is a port of lbugnion's sample-azure-coinvalue to the current Azure Functions runtime, as well as the inclusion of Azure Application Insights and custom metrics for Bitcoin and Ethereum prices.

Prerequisites

Regardles of platform and IDE you will have to install the .Net Core SDK and the current Azure Functions Core Tools. Which version of the SDK you need, depends on the version of function you want to develop: Version overview. This project uses the 2nd version of Azure Functions.

Visual Studio Code

When using Visual Studio Code (which is my preferred way), you will need some extensions to work with Azure Functions and ARM templates. The ones I would recommend before getting started, are listed below:

The ARM Template Viewer gives you a nice visualization of your deployment and is thus beneficial alongside the code during development of the template. The visualization for this project is given below:

ARM template visualization

Visual Studio

When using Visual Studio, you will only need to make sure that you use the latest version (currently 2019) and have checked ASP.NET and web development, as well as Azure development during the installation process. If you have Visual Studio installed but have not used these SDKs as of yet, make sure to install them now.

Visual Studio 2019 installer

If you want to make visualizations of your ARM template during development, as is possible in Visual Studio Code, you will need to use the ARMVIZ visual designer. Just upload your current progress there vis File > Open Local Template .... It is also possible to develop your templates from therem, but the tradeof that has to be made is that templates created there can not be tested instantly.

Run the demo

Deploy to Azure Visualize

You can press the button above to automatically deploy the prepared ARM template in Azure. Alternatively make sure that you have the Azure Functions runtime installed, as well as the Azure storage emulator (only needed when only using Visual Studio Code), due to the fact that Functions rely heavily on Azure Storage Accounts.

If you want to have a look at the table this example populates and uses during runtime, make sure to have the Azure Storage Explorer installed.

Important: The button above only deploys the infrastructure on Azure. You will need to push the code yourself! In oder to push the code of the Azure Function use Visual Studio Code or Visual Studio with their respective methods for deploying to Azure.

Running locally

Using an IDE

Open the project in your preferred IDE. I will use Visual Studio Code here, but following along in Visual Studio should be just as easy. You then can press F5 to build and debug the function locally. The REST endpoint of the function will be available on http://localhost:7071/api. You can set breakpoints from here and dig into the code.

Using the console

This is also a completely valid method of running the app in a local environemt, if for example you want to use something like Sublime Text. In order to get started navigate to the project directory. Open up a terminal of your preference here and enter dotnet restore first, in order to grab all the latest packages from nuget. Once done you can complie the code using dotnet build. This results in a CoinValue.dll in ./bin/Debug/netcoreapp2.1/bin. In order to run the function, navigate there and run func host start CoinValue.dll

Deploying to Azure

If you want to publish the app to Azure you can do so by right clicking in either Visual Studio Code or Visual Studio and selecting either Deploy to Function App ... or Deploy .... In any case a wizard will pop up, that helps you setting up the respective resources that are needed for deployment. Afterwards the code will be pushed to the respective resources and form there is ready to go. Once you made changes that you want to publish to Azure, simply rerun the steps above.

Information

This Azure functions ever minutes takes a snapshot of the current Bitcoin and Ethereum prices from CoinMarketCap and saves them to an Azure Table Storage. Important: Do not use the one minute trigger in production, it will kill your Azure credit long term. The latest price including information on whether the price is falling or rising, can then be retrieved via REST endpoints. The respective endpoint s are:

Valid symbols are either btc or eth. But feel free to try others and produce unexpected behavior 😄

Usefull resources

Azure Functions

Application Insights

ARM Templates