Write data to external database

write-data-to-external-database-lambda

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.


Write data to external database

To write data to an external database, follow below steps:

  1. Download our example functions.py below and modify it as per your needs
  2. 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:

  1. Lets you input connection parameters for the database
  2. Load all messages into resampled data frame
  3. Use message name as signal prefix (to ensure global uniqueness)
  4. Restructure the data frame into a compatible format
  5. 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