Introduction to Azure Functions
Azure Functions provide easy way how to run serverless functions (small pieces of code) in Azure. You can run your C#/Javascript/F#/Java/Python function with HTTP/DB/queue/file trigger integration. Sample Function:
|
|
Dev environment
Microsoft created nice cross-platform environment for developers. You are able to develop and debug Azure Functions on Windows/Linux/Mac with Visual Studio (Code). For testing and debugging you can use Azure Functions Core Tools (func.exe/func).
To install AFCT via npm use command:
|
|
But this dev environment requires connection strings to Azure Storage for writing metadata about functions (locks, timers or even log outputs from functions) – variables AzureWebJobsStorage
and AzureWebJobsDashboard
in local.settings.json
file.
Options
Azure Storage Emulator
A service, which emulates Azure’s Storage API (usually is installed with Azure SDK) and can be installed on any Windows computer.
In that case use for both variables value:
"UseDevelopmentStorage=true"
++ no costs −− dependency on Windows, stability (especially for concurrent clients)
Azure Storage Acccount
straightforward solution: just create another Storage in Azure and use it for development.
++ easy configuration, same behavior as production −− you have to be online with connection to Azure to run and debug your function
Microsoft’s (production) runtime environment
For production Azure Functions apps Microsoft created more runtime environments. When you deploy your Function to Azure, you can choose between Windows and Linux runtime. Both runtime are available as Docker container image on GitHub.
But they have same issue as dev environment – they needs connection strings to Azure Storage for writing metadata about functions (locks, timers or even log outputs from functions) – variables AzureWebJobsStorage
and AzureWebJobsDashboard
in local.settings.json
file.
Q: So how can I run production server on own infrastructure totally without connection to Azure?
A: You can’t, at least for now. Depedency to Azure Storage is too much strong at the moment.
Introducing Vasek’s AF Host Docker image
But you can get close to that. For this purpose I created my custom runtime Docker image for Azure Functions applications – to have better experience with applications deployed on own infrastructure.
This image is based on Microsoft’s official docker runtime image, but with some modifications – e.g. redirected logs to console, exit code for Docker,…
So result is, that for runtime you need only Azure Storage Account for metadata (AzureWebJobsStorage
).
Installation
Installation is easy – instead of official docker image use for runtime my image vjirovsky/vaseks-af-host:{runtimelanguage}-{version}
For dotnet runtime v2.0: FROM vjirovsky/vaseks-af-host:dotnet-2.0
Sample project based on Vasek’s AF Host image
|
|
You can find out sample project on GitHub.
Sample run (of app sample-app):
|
|
Source code
Source code of Vasek’s Azure Functions Host runtime is available on GitHub.