- Newest
- Most votes
- Most comments
To achieve your goal of storing data in Amazon Timestream at 15-minute intervals from your IoT device that sends data every 2 to 3 seconds, you'll need to modify your existing setup and potentially incorporate additional AWS services. Here's a step-by-step approach to accomplish this:
- Modify your existing AWS IoT Core rule:
- Keep your current rule that routes data to Timestream, but add a condition to filter messages based on a timestamp.
- In the SQL statement of your rule, use a function like
timestamp()or extract the timestamp from your payload, and use theMODfunction to only process messages at 15-minute intervals.
Example SQL statement:
SELECT * FROM 'iot/topic' WHERE MOD(FLOOR(timestamp() / 60000), 15) = 0
This will only process messages when the minute is divisible by 15 (i.e., every 15 minutes).
- Create an AWS IoT Analytics pipeline:
- Set up an IoT Analytics channel to ingest your IoT data.
- Create a pipeline that includes an activity to filter messages based on the 15-minute interval.
- Add a datastore to temporarily hold the filtered data.
- Create an IoT Analytics dataset:
- Set up a dataset with a schedule trigger to run every 15 minutes.
- Configure the dataset to query the datastore and select the most recent data point within the 15-minute window.
- Use AWS Lambda with IoT Analytics:
- Create a Lambda function that is triggered by the IoT Analytics dataset.
- This function will receive the dataset content (the selected data point) and write it to Timestream.
- Set up IAM roles and permissions:
- Ensure that your IoT Core rule has permissions to write to IoT Analytics.
- Grant necessary permissions to the Lambda function to read from IoT Analytics and write to Timestream.
This approach allows you to continue receiving all data from your IoT device while selectively storing data points at 15-minute intervals in Timestream. The IoT Analytics pipeline and dataset provide the mechanism for time-based data selection, while Lambda gives you the flexibility to process and store the data as needed.
Remember to adjust the exact implementation details based on your specific payload structure and requirements. You may need to fine-tune the SQL queries and Lambda function logic to ensure you're selecting the most appropriate data point for each 15-minute interval.
Sources
Using the CreateDataset API via Java and the AWS CLI - AWS IoT Analytics
AWS IoT Core - Amazon Timestream
Relevant content
- asked a year ago

SELECT * FROM 'iot/topic' WHERE MOD(FLOOR(timestamp() / 60000), 15) = 0, using this SQL gives data at 15th minute. But gives other packets from 0th sec to 59th sec. Here we need only first 0th or 1st sec packet. How we can achieve this?