Time Series Data Management with Amazon Timestream
Amazon Timestream is AWS's family of managed databases for time-series data, and it consists of two engines: the serverless Timestream for LiveAnalytics and Timestream for InfluxDB, which offers managed InfluxDB. Because every sensor record is tied to a timestamp, these databases handle filtering by time range, downsampling and moving older data to cheaper storage out of the box. An important note: AWS closed LiveAnalytics to new customers as of June 20, 2025; Timestream for InfluxDB is recommended for new projects, while existing LiveAnalytics customers can continue to use it.
In this article we look at both engines for storing measurements from our ZMA Data Acquisition and GDT Digital Transmitter devices, in the context of our Cloud & IoT Data Collection Solutions.
Why a time-series database for sensor data?
General-purpose relational databases (MySQL, PostgreSQL) can store sensor data, but as the data grows the following jobs become your responsibility:
- Partitioning: Splitting the table by time and dropping old partitions.
- Aggregation: Extra indexes and summary tables for queries such as "per-minute average over the last 24 hours."
- Retention policy: Moving old data to cheaper storage or deleting it.
- Scaling: Growing the server as the write rate increases.
Time-series databases provide these out of the box: time-based retention policies, time functions such as bin() / ago(), interpolation, and compression designed for time series. On the PostgreSQL side, the TimescaleDB extension offers a similar route; the choice depends on your team's operational preferences.
What is the difference between the LiveAnalytics and InfluxDB engines?
| Feature | Timestream for LiveAnalytics | Timestream for InfluxDB |
|---|---|---|
| New customers | Closed since June 20, 2025 | Open, AWS's recommended option |
| Operating model | Serverless, scales automatically | Managed DB instance of a size you choose |
| Query language | SQL | InfluxDB query languages (by version) |
| Storage tiers | Memory store → Magnetic store | Instance storage, retention policy |
| IoT Core rule integration | Direct Timestream action | Via Lambda or an intermediate layer |
| Grafana | Timestream plugin | Built-in InfluxDB data source |
The examples below are for existing accounts that use LiveAnalytics. The data model concepts (device dimension/tag, measure fields, time windows) carry over to InfluxDB, but SQL queries using BIN, ago and INTERPOLATE_LINEAR must be rewritten in InfluxDB's query language.
How is data organised in LiveAnalytics?
AmazengFactory (Database)
├── SensorData (Table)
│ ├── Memory Store: 7 days (fast access, real-time dashboards)
│ └── Magnetic Store: 2 years (archive, historical analysis)
├── Alarms (Table)
└── ProductionMetrics (Table)
Data is written to the memory store first; when its retention period expires it moves automatically to the magnetic store, and when that period expires it is deleted. The memory store is designed for high-throughput writes and querying recent data, the magnetic store for long-term, lower-cost storage. Writing late-arriving data with timestamps older than the memory store window requires enabling magnetic store writes on the table.
Creating the table
aws timestream-write create-database \
--database-name AmazengFactory \
--region eu-west-1
aws timestream-write create-table \
--database-name AmazengFactory \
--table-name SensorData \
--retention-properties '{
"MemoryStoreRetentionPeriodInHours": 168,
"MagneticStoreRetentionPeriodInDays": 730
}'
How do you write IoT Core data to Timestream?
The AWS IoT Core rules engine can route MQTT messages to Timestream without writing code:
-- IoT Rule SQL
SELECT
values.channel_1 as ch1,
values.channel_2 as ch2,
values.channel_3 as ch3,
values.channel_4 as ch4
FROM 'amazeng/factory/+/data'
Action: Write to Timestream
{
"roleArn": "arn:aws:iam::123456789:role/IoTTimestreamRole",
"databaseName": "AmazengFactory",
"tableName": "SensorData",
"dimensions": [{ "name": "device", "value": "${device_name}" }],
"timestamp": {
"value": "${timestamp}",
"unit": "MILLISECONDS"
}
}
The rule writes each field selected in the SELECT as a separate measure, and dimensions lets you group records by device.
Multi-measure writes from the gateway with Python
Combining values read at the same moment into a single multi-measure record reduces the record count and simplifies queries:
import time
import boto3
client = boto3.client('timestream-write', region_name='eu-west-1')
def write_sample(device, ch_values):
record = {
'Time': str(int(time.time() * 1000)),
'TimeUnit': 'MILLISECONDS',
'Dimensions': [{'Name': 'device', 'Value': device}],
'MeasureName': 'channels',
'MeasureValueType': 'MULTI',
'MeasureValues': [
{'Name': f'ch{i}', 'Value': str(v), 'Type': 'DOUBLE'}
for i, v in enumerate(ch_values, 1)
],
}
client.write_records(DatabaseName='AmazengFactory',
TableName='SensorData', Records=[record])
write_sample('ZMA-Tank1', [45.2, 46.1, 44.8, 45.5])
A single WriteRecords call can carry at most 100 records; for high-frequency data, buffering records on the gateway and sending them in batches significantly reduces the number of API calls.
Which queries are most useful?
The queries below assume the multi-measure model from the Python example (columns ch1...ch4). For single-measure records written by the IoT rule, use a measure_name = 'ch1' filter and the measure_value::double column instead.
Per-minute average, minimum and maximum:
SELECT device,
BIN(time, 1m) AS minute,
AVG(ch1) AS avg_ch1, MIN(ch1) AS min_ch1, MAX(ch1) AS max_ch1
FROM "AmazengFactory"."SensorData"
WHERE time > ago(1h) AND measure_name = 'channels'
GROUP BY device, BIN(time, 1m)
ORDER BY minute DESC
Filling gaps with linear interpolation:
SELECT device,
INTERPOLATE_LINEAR(
CREATE_TIME_SERIES(time, ch1),
SEQUENCE(min(time), max(time), 1m)
) AS ch1_filled
FROM "AmazengFactory"."SensorData"
WHERE time > ago(1h) AND device = 'ZMA-Tank1'
GROUP BY device
Simple anomaly detection with a z-score (|z| > 3 against the last 7 days' statistics):
WITH stats AS (
SELECT AVG(ch1) AS mean, STDDEV(ch1) AS sd
FROM "AmazengFactory"."SensorData"
WHERE time > ago(7d) AND device = 'ZMA-Tank1'
)
SELECT time, ch1, (ch1 - stats.mean) / stats.sd AS z_score
FROM "AmazengFactory"."SensorData", stats
WHERE time > ago(1h) AND device = 'ZMA-Tank1'
AND ABS((ch1 - stats.mean) / stats.sd) > 3
Always include a time filter in queries; the amount of data scanned determines both duration and cost.
How do you visualise it with Grafana?
grafana-cli plugins install grafana-timestream-datasource
Rather than entering access keys in the data source, it is safer to use an IAM role attached to the server Grafana runs on. An example panel query:
SELECT BIN(time, $__interval_ms) AS time, AVG(ch1) AS value
FROM $__database.$__table
WHERE $__timeFilter AND device = 'ZMA-Tank1'
GROUP BY BIN(time, $__interval_ms)
ORDER BY time
For dashboard design, see our article on industrial data visualisation with Grafana.
How much data does a real scenario produce?
Scenario: 10 devices, 4 channels per device, one reading per second.
| Model | Calculation | Records per month (30 days) |
|---|---|---|
| Single-measure (one record per channel) | 10 × 4 × 86,400 × 30 | ≈ 103.7 million |
| Multi-measure (one record per device) | 10 × 86,400 × 30 | ≈ 25.9 million |
Assuming ~100 bytes per record, the multi-measure model produces about 2.6 GB of raw data per month; with 2-year retention that exceeds 60 GB before compression. This table is the basis of any cost estimate: record count drives write cost, retention drives storage cost, and query habits drive query cost. Since unit prices vary by region and pricing model, we recommend running the numbers against the current AWS pricing page.
Three ways to reduce cost
- Use multi-measure records: Cuts the record count by the number of channels.
- Summarise at the edge: Send per-second average/peak values, not the raw 1 kHz stream.
- Size retention to need: Keep the memory store only as long as real-time dashboards require.
Summary: checklist for choosing a time-series database
- Does your account already have LiveAnalytics? If not, start with Timestream for InfluxDB or another time-series solution.
- Design the data model (device dimension, measure fields) as multi-measure from the start.
- Set retention periods based on hot/cold data needs.
- Make a time filter mandatory in queries.
- Use IAM roles instead of access keys for Grafana and other clients.