AWS Lambda
An example integration where a Data Connector forwards events to an AWS Lambda Function.
Last updated
Was this helpful?
An example integration where a Data Connector forwards events to an AWS Lambda Function.
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 function will verify both the origin and content of the request using a , then decode the data.
We will create, configure, and deploy our Lambda function using the AWS Console, but the deployment package that contains the code and related runtime must be built locally on your machine. You must therefore have a working development environment.
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 .
AWS Lambda Functions can be created and deployed using either a Docker Image or a .zip archive. Both will achieve the same result, but we will here use a .zip archive in the interest of simplicity.
Create and enter a new root directory in which your function will be developed.
From inside your function root directory, install the following dependencies.
Your directory tree should now look something like this.
The following steps create the deployment package .zip archive.
From your directory root, create the deployment package with the following command.
We are now ready to create our new Lambda function. In the AWS web Console, find the Lambda service and click Create function and set the following parameters.
Select Author from scratch and set the following Basic Information.
Function name: As desired.
Runtime: Python 3.10
Click Create function to move onward to configuration.
Anything not mentioned here can be left default or changed as desired.
Under the Configuration tab, click Triggers and then Add trigger. Choose the API Gateway source with the following parameters.
Intent: Create a new API
API type: HTTP API
Security: Open
Click Save and note the URL. We will need it later.
Under the Configuration tab, click Environment variables and then Edit. Add a signature secret.
Name: DT_SIGNATURE_SECRET
Value: A unique password. We will need it later, so write it down.
Leaving Encryption configuration default will let AWS handle encryption at rest, but you can choose to handle the master key if you so desire.
Endpoint URL: The API endpoint URL found in the previous step.
Signature Secret: The value of DT_SIGNATURE_SECRET parameter 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 AWS environment, and you can start using it in their various services. Fortunately, AWS 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 Lambda Function to execute queries.
In your directory root, create a new file lambda_function.py with the following content. The implementation is explained in detail on the page.
In your directory root, create a file index.js in which you paste the following snippet. The implementation is explained in detail on the page.
The following steps are for Linux and MacOS. If you're on Windows or want more details about the process, refer to the .
To continuously forward the data to our newly created Lambda 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.
AWS provides a host of tools that can be used to . Check the logs for any tracebacks that could explain why an error is returned.
.
.