Azure HTTP Triggers
An example integration where a Data Connector forwards events to an Azure HTTP Trigger.
Last updated
Was this helpful?
An example integration where a Data Connector forwards events to an Azure HTTP Trigger.
Last updated
Was this helpful?
This example uses a Data Connector to forward the events of all devices in a project to an . When receiving the HTTPS POST request, our trigger will verify both the origin and content of the request using a , then decode the data.
The following points are assumed.
You have a of Project Developer or higher in your DT Studio project.
You are familiar with the and know how to .
You are familiar with the .
Depending on the runtime, parts of creating the HTTP Trigger must be done in a local environment on your machine. Ensure you have a working runtime environment for development using either the or .
Function Apps combine several functions into a single unit for easier management and can be created in the Azure Portal by . Create a new Function App with the following configurations.
Runtime Stack: Python
Version: 3.11
Operating System: Linux
Click Review + create, then Create and wait for deployment. Once deployed, Go to resource.
Name: DT_SIGNATURE_SECRET
Value: A unique password. We will use it later, so write it down.
Once the Function App is deployed, a new HTTP trigger function can be created. Azure has guides on creating and editing functions. Follow either.
By following one of the guides, create a new HTTP Trigger with the following configurations.
Authorization level: Anonymous.
Afterward, your project structure should end up looking something like this.
Once the function has been created, the desired behavior can be programmed. The following code snippet implements a simple HTTP trigger that listens for POST requests, then validates the content and origin using the Signature Secret and Checksum verification.
Dependencies must be specified and included for your HTTP Trigger to run in the cloud.
Once the function is deployed, the Invoke URL is displayed in the output. Copy and save it as we will need it when creating our Data Connector.
Endpoint URL: The Invoke URL found in the previous step.
Signature Secret: The value of DT_SIGNATURE_SECRET environment variable set earlier.
Depending on your integration, it can also be smart to disable the event types you are not interested in. For instance, the NetworkStatusEvent is sent every Periodic Heartbeat and will by default be forwarded by the Data Connector if not explicitly unticked.
If instead the Error counter increments, a response containing a non-200 status code is returned.
Verify that the Data Connector endpoint URL is correct.
Your sensor data is now in the Azure environment, and you can start using it in their various services. Fortunately, Azure has some well-documented guides to get you started.
A database should be tailored to each specific use case. However, if you're uncertain, PostgreSQL (Postgres) is a good place to get started. The following guides will show you how to create a new Postgres database, then connect your HTTP Trigger to execute queries.
We will verify the incoming POST request by a signature secret, as explained in the Data Connector . In your new Function App, add a secret to your App environment by adding a new Application Setting, .
In your HTTP Trigger function directory, edit the file __init__.py
. The implementation is explained in detail on the page.
In your HTTP Trigger function directory, edit the file __init__.py
. The implementation is explained in detail on the page.
In your HTTP Trigger function directory, edit the file index.js
. The implementation is explained in detail on the page.
As explained , edit requirements.txt
to tell Azure which dependencies to install.
As explained , edit requirements.txt
to tell Azure which dependencies to install.
As explained , in your project directory, install all requisite packages locally using npm install
. This will generate a directory node_modules which is included when deploying.
Your function should now be ready for deployment. It is considered good practice to test- and experiment with your function locally, . The following command will deploy your function to the Function App created in the beginning.
To continuously forward the data to our newly created Cloud Function, a Data Connector with almost all default settings is sufficient. If you are unfamiliar with how Data Connectors can be created, refer to our guide. The following configurations should be set.
If the integration was correctly implemented, the Success counter for your Data Connector should increment for each new event forwarded. This happens each or by touching a sensor to force a new event.
Azure provides a host of tools that can be used to . Check the logs for any tracebacks that could explain why an error is returned.
.
.