This repository serves as an example of an AWS Lambda time-series application that uses TimescaleDB on Timescale Cloud as a database!
The application consists of two Lambda functions behind an API Gateway and a TimescaleDB instance on Timescale Cloud.
This function takes in an API Gateway event with a body containing the location and temperature of the sensor reading. The function parses those parameters from the body and inserts them into a TimescaleDB database.
Event body:
{ "location": "bedroom", "temperature": 74 }Response:
[ { "time": 1675997918, "location": "bedroom", "temperature": 65.0 }, ... { "time": 1675997910, "location": "bedroom", "temperature": 67.0 } ]This function takes no inputs but returns the latest 5 sensor readings ordered by time in an array.
In order to use this AWS SAM project, you need to modify the following records in the template.yaml file:
Globals.Function.Environment.Variables.CONN_STRINGGlobals.Function.Environment.VpcConfig.SecurityGroupIdsGlobals.Function.Environment.VpcConfig.SubnetIds
To test the functions locally we need to build the Docker container for each function. You can do this by executing the following command in the root of this project:
sam buildAfterwards we can test each function individually using the provided events in ./events.
# test the PostSensorData function sam local invoke "PostSensorDataFunction" -e events/post.json # test the GetSensorData function sam local invoke "GetSensorDataFunction" -e events/get.jsonTo deploy the function and it's required resources for the first time, execute:
sam deploy --guided If you've made changes to the code and want to deploy them to the cloud, execute:
sam build sam deploy 
