This is an old revision of the document!
Table of Contents
Azure function
Setting up IDE: Visual Studio Code
Use to reload the env variables after installing
$env:Path = ` [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + ` [System.Environment]::GetEnvironmentVariable("Path","User")
Install packages locally, to make imports succeed
pip install -r .\requirements.txt
Make sure you select the right python version, for which you executed the “pip install”
Then even under windows one can run “func start” to test linux functions
func start
Debugging Azure functions
You can execute the Azure functions from the portal.
And you can validate the behavior via “Portal > Azure Function > Log Stream”
Azure functions in Azure Portal
The trigger and code.
Only available after uploading the code into the function, via
az functionapp deployment source config-zip -g $resourceg -n $functionname –src app.zip
which uploads the app.zip
into the associated blob-container,
from where it automatically is executed by the azure_function.
Here the function http_trigger
was recognized.
Limitations of Azure functions
- Azure functions - are NOT only serverless.
- You can choose a premium subscription and deploy your Azure function as an always running instance into your network
- You CAN'T use a serverless function - in a private network
- You CAN'T have multiple triggers for a function. ONly one of
- http_trigger
- Blob trigger
- CosmosDB trigger
- EventHub trigger
- Queue trigger
- ServiceBus Queue trigger
- ServiceBus Topic trigger
- Timer Trigger
Serverless Azure functions
Python linux functions
func start
IN general read about developing locally: https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local
Azure Service Bus Pub/Sub
Publishing function
import logging import azure.functions as func app = func.FunctionApp() # vs output into queue for python # https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-output?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cextensionv5&pivots=programming-language-python @app.route(route="http_trigger_queue", auth_level=func.AuthLevel.ANONYMOUS) @app.service_bus_queue_output(arg_name="message", connection="ServiceBusConnection", queue_name="alfdevapi5servicebusqueue") def http_trigger_queue(req: func.HttpRequest, message: func.Out[str]) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') logging.info('Python HTTP trigger function processed a request.') myMessage = "Hi alf this is my message via the queue to you." logging.info(myMessage) input_msg = req.params.get('message') message.set(f"{myMessage} {input_msg}") return func.HttpResponse( "This function should process queue messages.", status_code=200 )
Subscribing function
import logging import azure.functions as func app = func.FunctionApp() @app.service_bus_queue_trigger(arg_name="azservicebus", queue_name="alfdevapi5servicebusqueue", connection="ServiceBusConnection") def servicebus_trigger(azservicebus: func.ServiceBusMessage): logging.warn('Python ServiceBus Queue trigger processed a message: %s', azservicebus.get_body().decode('utf-8'))
Here you can see, that when the publishing function is executed, via Test
Then the consuming function is receiving the message from the queue.