Azure Functions with different Azure services

Introduction

If you are like me, a newbie in the serverless world, the first thought is probably to read through all official documentation you can find related with Azure Functions. However, I was not able to successfully create and run an Azure Function just based on the instructions provided by the official documentation. Maybe it is just a personal situation. I spent a decent amount of time pulling information from different places and I was able to eventually understand Azure Functions’ basics and make it run the way I want.

Image Source: Guidance for developing Azure Functions | Microsoft Docs

HTTP Trigger

Usually, users develop Azure Functions in an Integrated Development Environment (IDE) such as Visual Studio Code (VS Code). However, with the latest features, users can actually create a C# Azure Functions with just Azure portal. Since I am familiar with Python, I will demonstrate everything from VS Code.

python3 -m venv <virtual env. name> 
pip install -r requirements.txt
func start
http://localhost:7071/api/jonwhttptrigfunc3
#create a resource group
az group create --name <RG_NAME> --location <LOCATION>
#create a storage account
az storage account create --name <STORAGE_NAME> --sku Standard_LRS
az functionapp create -g <RG_NAME> --consumption-plan-location <LOCATION_NAME> --runtime python --runtime-version 3.8 --functions-version 3 --name <APP_NAME> --os-type linux --storage-account <STORAGE_NAME>
func azure functionapp publish <APP_NAME>

Queue Storage Trigger

The way to set up Azure Functions with queue storage is almost identical to Azure Functions with HTTP trigger except for the fact that the application will need to bind with the input and output queue storage.

#create an input queue storage
az storage queue create -n <input_queue_name> --account-name <storage_name>
#create an output queue storage
az storage queue create -n <output_queue_name> --account-name <storage_name>
{ "text": "abc" }
#create a resource group
az group create --name <RG_NAME> --location <LOCATION>
#create a storage account
az storage account create --name <STORAGE_NAME> --sku Standard_LRS
az functionapp create -g <RG_NAME> --consumption-plan-location <LOCATION_NAME> --runtime python --runtime-version 3.8 --functions-version 3 --name <APP_NAME> --os-type linux --storage-account <STORAGE_NAME>
func azure functionapp publish <APP_NAME>

Timer Trigger

Timer-trigger Azure Functions are having really similar setups like the 2 above. The only thing that will need extra attention is the settings in “function.json” that is using CRON schedule syntax.

{  
"scriptFile": "__init__.py",
"bindings": [
{ "name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "* */10 * * * *"
}
]
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jonathan

Learning new things about Kubernetes every day. Hopefully, the learning notes could help people on the same journey!