Skip to content

ScheduledQuery

Source: src/AWS/Timestream/ScheduledQuery.ts

An Amazon Timestream for LiveAnalytics scheduled query — a SQL query Timestream runs on a cron/rate schedule, materializing results into a target table and notifying an SNS topic after each run.

Only the state (ENABLED/DISABLED) is mutable in place; changing the query, schedule, notification topic, role, target, error report location, or KMS key replaces the scheduled query. Tags sync in place.

Hourly Rollup

import * as Timestream from "alchemy/AWS/Timestream";
const rollup = yield* Timestream.ScheduledQuery("HourlyRollup", {
queryString: `SELECT host, AVG(measure_value::double) AS avg_cpu
FROM "metrics"."cpu"
WHERE time > ago(1h) GROUP BY host`,
scheduleExpression: "rate(1 hour)",
notificationTopicArn: topic.topicArn,
executionRoleArn: role.roleArn,
errorReportS3: { bucketName: bucket.bucketName },
targetConfiguration: {
TimestreamConfiguration: {
DatabaseName: database.databaseName,
TableName: rollupTable.tableName,
TimeColumn: "time",
DimensionMappings: [{ Name: "host", DimensionValueType: "VARCHAR" }],
MultiMeasureMappings: {
TargetMultiMeasureName: "cpu_rollup",
MultiMeasureAttributeMappings: [
{ SourceColumn: "avg_cpu", MeasureValueType: "DOUBLE" },
],
},
},
},
});

Pausing a Schedule

const rollup = yield* Timestream.ScheduledQuery("HourlyRollup", {
// ... unchanged configuration ...
state: "DISABLED",
});