AWS Lambda functions are a smart way to auto-execute code on every log file upload.
Below we describe how you can set up an AWS Lambda function to automatically run the script when a new log file is uploaded.
This is an advanced topic and we recommend that you get the basics in place first:
inputs.py
and InfluxDB account settings are setup as needed (see below)The canedge-influxdb-writer script relies on a number of dependencies that need to be provided to the AWS Lambda function. To make this easy, we have pre-built ‘layers’ for the major AWS S3 regions. You can find the latest layer list in our Releases page. See below for details. By providing your AWS Lambda function with an ‘ARN identifier’ for a pre-built layer, you ensure that all relevant dependencies are in place. The ARN should match the region that your S3 bucket is setup in.
If you’re initially testing your setup with a free InfluxDB Cloud starter account, keep in mind that there is a ‘write restriction’ of 5 MB per 5 minutes. This means that if you try to write e.g. 30 MB of data, it will take > 30 minutes. This exceeds the AWS Lambda max timeout. If you’re using AWS Lambda, we recommend that you ensure your log file split size is 2-5 MB and that the data you extract is optimized (i.e. only push relevant signals at relevant resampled frequency). Depending on your use case, this will let you set up a basic PoC.
For ‘production setups’, we recommend self-hosting InfluxDB or using a paid InfluxDB Cloud if you wish to use AWS Lambda function.
AWSLambdaBasicExecutionRole
+ AmazonS3FullAccess
All object create events
and suffix .MF4
lambda_function.py
, utils.py
, utils_db.py
, inputs.py
and your *.dbc
(ensure your inputs are updated)lambda_layer_arns.csv
file3 min
and memory to 1024 MB
(you can test/tweak these later)Once tested, change the ‘Trigger’ S3 bucket to your main bucket and verify that it works as intended over a period.
{
"Records": [
{
"s3": {
"bucket": {
"name": "your-source-bucket-name",
"arn": "arn:aws:s3:::your-source-bucket-name"
},
"object": {
"key": "<device_id>/<test_file_session_id>/<full_test_file_name.MF4>"
}
}
}
]
}
Typical issues that may arise include the following:
We recommend tracking your AWS billing costs when working with Lambda functions to ensure everything is set up correctly. We do not take responsibility for incorrect implementations or unexpected costs related to implementation of the below. Note also that the below is intended as a ‘getting started’ guide - not a fully cost optimized setup.