Write data to external database
In this section we explain how you can customize your Lambda to write data to an external database via REST, enabling you to integrate your data with practically anything.
Table of Contents
Write data to external database
To write data to an external database, follow below steps:
- Download our example
functions.py
below and modify it as per your needs - Follow the steps to set up a custom Lambda function incl. ARN layer
external database writer function
Function explained
The example function does the following:
- Lets you input connection parameters for the database
- Load all messages into resampled data frame
- Use message name as signal prefix (to ensure global uniqueness)
- Restructure the data frame into a compatible format
- Post the data to the database
Note
The example is a basic starting point that takes outset in the InfluxDB database - you will need to modify sections to match the REST ingestion requirements of your database
REST vs. Python clients
The example takes outset in the REST API for writing data, which is supported by most databases for data ingestion. Many databases also offer a ‘Python client’ which you can alternatively use - but in this case notice that you will need to create an ARN layer to enable support for the library.
Alternatively, you may be able to leverage the existing functionality within the AWS SDK ARN layer as per their API documentation. Examples of supported databases are below:
- Amazon Redshift
- PostgreSQL
- MySQL
- Microsoft SQL Server
- DynamoDB
- Amazon Timestream