The following samples provides a webhook receiver, designed to run on Azure and handle messages from an ArcGIS Online Feature service (it will also support Portal webhooks). Once deployed to Azure, a secure, public URL allows webhooks to send payloads to the receiver. This sample will only listen for messages and write the output to the logger. Further development is required to complete the workflow. Within the samples, a copy of this has been enhanced to log payloads into an Azure Table. Alternatively you could write the messages into a Queue or make use of other Python modules to perform actions.
Note: The receiver will support the AGOL secret key
implementation of the SHA256 hash. Update the SECRETKEY
value in the hash_check.py
file. This implementation is specific to the ArcGIS Online secret key workflow. Portal webhooks do not make use of the 256 hash, as such the code would have to be updated to listen and respond to a secret key from Portal. The receiver you deploy as a function will be available to anyone who can find the URL unless you take steps to secure the endpoint. Various mechanisms within Azure Functions and Azure itself exist, however these topics are not covered here.
Before attempting to deploy the Azure function, you'll need to setup your environment. This sample makes use of Python and VS Code to create an Azure Function. Follow the Getting started with Azure Functions guide and the Quickstart: Create a function in Azure with Python using VS Code before continuing with the steps below. A subscription to Azure is also required.
- Install Python (Version 3.7 - 3.9 only)
- Install VS Code
- Install Azure Function Core Tools
- VS Code Python Extension (from market place) Select the Python interpreter you installed in step 1
- VS Code Azure Functions Extension (from market place)
The code from the repository should be copied to an independent folder outside this repository as multiple Azure Functions exist.
-
From VS Code, select File > Open Folder and select the location of the copied Function. Trust the folder to proceed.
-
If you receive a message informing about a failed virtual environment, create a new one and select your Python interpreter.
You can test the function locally by pressing F5. Once ready, the receiver will be available at
http://localhost:7071/api/Hook
-
Select the Azure extension (
shift-alt-a
) and Sign in to Azure or Create a free trail -
Expand Local Project > Functions and verify that the Hook function exists. The function is an anonymous httpTrigger.
-
Click the Function deploy button on the Azure extension (cloud with up arrow) and select Create a new function app in azure advanced
-
Provide a unique name. The name will be used within the URL of your receiver.
eg.
https://NAME.azurewebsites.net/api/hook
-
Select a runtime. (Match the version of Python installed)
-
Create a new or select an existing resource group
-
Select a location (eg. US East)
-
Choose the consumption plan
-
Create a new storage account an provide a name
-
Create an application insight (optional this could be useful if you need to debug or stream logs on portal.azure.com)
-
The function will be uploaded to Azure (it could take a few minutes to deploy)
Chase Clark, GIS Analyst at Stantec presented a video, Integrating webhooks, serverless functions and web tools for real-time updates describing the use of an Azure Function to handle webhook responses.