AWS.Timestream reference
CancelQuery
Section titled “CancelQuery”Source:
src/AWS/Timestream/CancelQuery.ts
Runtime binding for timestream-query:CancelQuery — cancel a running query
by the QueryId a previous Query call reported.
timestream:CancelQuery does not support resource-level permissions, so
this is an account-level binding invoked with no resource argument.
Provide Timestream.CancelQueryHttp on the Function to implement the
binding.
CancelQuery: Querying Data
Section titled “CancelQuery: Querying Data”// init — account-level binding, no resource argumentconst cancelQuery = yield* Timestream.CancelQuery();
// runtime — cancel by the QueryId from a prior Query responseconst result = yield* cancelQuery({ QueryId: queryId });// result.CancellationMessage reports whether the query was still runningCreateBatchLoadTask
Section titled “CreateBatchLoadTask”Source:
src/AWS/Timestream/CreateBatchLoadTask.ts
Runtime binding for timestream-write:CreateBatchLoadTask — start a bulk
CSV import from S3 into a Timestream Table.
Bind the operation to the target table to get a callable with
TargetDatabaseName and TargetTableName injected automatically; you
supply the S3 data source, the report location, and the data model. The
binding grants timestream:CreateBatchLoadTask on the table and its
database; grant the host S3 read on the source bucket and write on the
report bucket separately (e.g. via the S3 capability bindings).
Provide Timestream.CreateBatchLoadTaskHttp on the Function to implement
the binding.
CreateBatchLoadTask: Batch Loading
Section titled “CreateBatchLoadTask: Batch Loading”// init — bind the operation to the target tableconst createBatchLoadTask = yield* Timestream.CreateBatchLoadTask(table);
// runtime — import CSV rows from S3const task = yield* createBatchLoadTask({ DataSourceConfiguration: { DataSourceS3Configuration: { BucketName: "my-ingest-bucket", ObjectKeyPrefix: "metrics/" }, DataFormat: "CSV", }, ReportConfiguration: { ReportS3Configuration: { BucketName: "my-report-bucket" }, }, DataModelConfiguration: { DataModel: { TimeColumn: "time", TimeUnit: "MILLISECONDS", DimensionMappings: [{ SourceColumn: "host" }], MeasureNameColumn: "measure" } },});// task.TaskId identifies the import for Describe/ResumeDatabase
Section titled “Database”Source:
src/AWS/Timestream/Database.ts
An Amazon Timestream for LiveAnalytics database — the top-level container for
time-series Tables.
Database owns the database’s lifecycle and its mutable configuration: the
KMS key used for encryption at rest and its tags. A database name is
auto-generated from the app, stage, and logical ID unless you provide one.
Database: Creating Databases
Section titled “Database: Creating Databases”Basic Database
import * as Timestream from "alchemy/AWS/Timestream";
const database = yield* Timestream.Database("Metrics");Database with a Customer-Managed KMS Key
const database = yield* Timestream.Database("SecureMetrics", { kmsKeyId: "alias/my-timestream-key", tags: { Environment: "production" },});DbInstance
Section titled “DbInstance”Source:
src/AWS/Timestream/DbInstance.ts
An Amazon Timestream for InfluxDB DB instance — a managed, single-tenant InfluxDB engine for time-series workloads.
DbInstance owns the instance’s lifecycle and its mutable configuration
(instance type, storage, port, parameter group, log delivery, deployment
type, and tags). Networking (subnets, security groups), the initial
credentials, organization, and bucket are fixed at creation.
DbInstance: Creating DB Instances
Section titled “DbInstance: Creating DB Instances”import * as Timestream from "alchemy/AWS/Timestream";
const influx = yield* Timestream.DbInstance("Influx", { name: "my-influx", dbInstanceType: "db.influx.medium", allocatedStorage: 20, vpcSubnetIds: [subnetA.subnetId, subnetB.subnetId], vpcSecurityGroupIds: [securityGroup.groupId], password: Redacted.make("super-secret-password"),});DescribeBatchLoadTask
Section titled “DescribeBatchLoadTask”Source:
src/AWS/Timestream/DescribeBatchLoadTask.ts
Runtime binding for timestream-write:DescribeBatchLoadTask — poll a bulk
import started by CreateBatchLoadTask for its status and progress
report.
Batch-load task reads are keyed by TaskId and authorized account-wide, so
this is an account-level binding invoked with no resource argument.
Provide Timestream.DescribeBatchLoadTaskHttp on the Function to implement
the binding.
DescribeBatchLoadTask: Batch Loading
Section titled “DescribeBatchLoadTask: Batch Loading”// init — account-level binding, no resource argumentconst describeBatchLoadTask = yield* Timestream.DescribeBatchLoadTask();
// runtimeconst described = yield* describeBatchLoadTask({ TaskId: task.TaskId });// described.BatchLoadTaskDescription?.TaskStatus === "SUCCEEDED"ExecuteScheduledQuery
Section titled “ExecuteScheduledQuery”Source:
src/AWS/Timestream/ExecuteScheduledQuery.ts
Runtime binding for timestream-query:ExecuteScheduledQuery — manually
run a ScheduledQuery for a given invocation time (e.g. to backfill
a window the schedule missed).
Bind the operation to the scheduled query to get a callable with
ScheduledQueryArn injected automatically.
Provide Timestream.ExecuteScheduledQueryHttp on the Function to
implement the binding.
ExecuteScheduledQuery: Creating Scheduled Queries
Section titled “ExecuteScheduledQuery: Creating Scheduled Queries”// init — bind the operation to the scheduled queryconst executeScheduledQuery = yield* Timestream.ExecuteScheduledQuery(rollup);
// runtime — re-run the rollup as-of one hour agoyield* executeScheduledQuery({ InvocationTime: new Date(Date.now() - 60 * 60 * 1000),});ListBatchLoadTasks
Section titled “ListBatchLoadTasks”Source:
src/AWS/Timestream/ListBatchLoadTasks.ts
Runtime binding for timestream-write:ListBatchLoadTasks — enumerate the
account’s bulk imports, optionally filtered by status.
Account-level binding invoked with no resource argument.
Provide Timestream.ListBatchLoadTasksHttp on the Function to implement
the binding.
ListBatchLoadTasks: Batch Loading
Section titled “ListBatchLoadTasks: Batch Loading”// init — account-level binding, no resource argumentconst listBatchLoadTasks = yield* Timestream.ListBatchLoadTasks();
// runtimeconst tasks = yield* listBatchLoadTasks({ TaskStatus: "IN_PROGRESS" });// tasks.BatchLoadTasks lists each task's TaskId and statusPrepareQuery
Section titled “PrepareQuery”Source:
src/AWS/Timestream/PrepareQuery.ts
Runtime binding for timestream-query:PrepareQuery — validate a SQL query
against a Timestream Table and inspect its result schema and
parameter mappings without running it.
Bind the operation to the table the SQL reads so the host is granted
timestream:PrepareQuery and timestream:Select on it (plus the unscoped
timestream:DescribeEndpoints the endpoint-discovery flow needs). The
query string itself still references the database and table by name.
Provide Timestream.PrepareQueryHttp on the Function to implement the
binding.
PrepareQuery: Querying Data
Section titled “PrepareQuery: Querying Data”// init — bind the operation to the table the SQL readsconst prepareQuery = yield* Timestream.PrepareQuery(table);
// runtime — validate only; Columns/Parameters describe the result shapeconst prepared = yield* prepareQuery({ QueryString: `SELECT COUNT(*) AS c FROM "${databaseName}"."${tableName}"`, ValidateOnly: true,});// prepared.Columns[0].Name === "c"Source:
src/AWS/Timestream/Query.ts
Runtime binding for timestream-query:Query — run SQL queries against a
Timestream Table.
Bind the operation to a table inside a function runtime to get a callable
that grants timestream:Select on the table (plus the unscoped
timestream:DescribeEndpoints the endpoint-discovery flow needs). The
query string itself still references the database and table by name.
Provide Timestream.QueryHttp on the Function to implement the binding.
Query: Querying Data
Section titled “Query: Querying Data”// init — bind the operation to the tableconst query = yield* Timestream.Query(table);
// runtime — run a SQL queryconst result = yield* query({ QueryString: `SELECT COUNT(*) AS c FROM "${databaseName}"."${tableName}"`,});// result.Rows / result.ColumnInfo hold the result setRecordsSink
Section titled “RecordsSink”Source:
src/AWS/Timestream/RecordsSink.ts
A batching sink over Timestream WriteRecords (100 records per call).
Timestream ingests the valid subset of each batch and reports invalid
records positionally via RejectedRecordsException (schema conflicts,
timestamps outside the retention window, version conflicts). Rejections are
permanent — the sink drops them (surfacing a warning with the rejected
count) and keeps draining; there is no transient per-record failure mode to
retry.
Provide Timestream.RecordsSinkHttp on the Function to implement the
binding.
RecordsSink: Streaming Records
Section titled “RecordsSink: Streaming Records”// init — bind the sink to the table; shared attributes are sent once per// batch as CommonAttributes and merged into every record server-sideconst sink = yield* Timestream.RecordsSink(table, { commonAttributes: { MeasureName: "cpu", MeasureValueType: "DOUBLE", TimeUnit: "MILLISECONDS", },});
// runtime — drain a stream through the sink (batched 100 records/call)yield* Stream.fromIterable( samples.map((s) => ({ Dimensions: [{ Name: "host", Value: s.host }], MeasureValue: `${s.value}`, Time: `${s.time}`, })),).pipe(Stream.run(sink));ResumeBatchLoadTask
Section titled “ResumeBatchLoadTask”Source:
src/AWS/Timestream/ResumeBatchLoadTask.ts
Runtime binding for timestream-write:ResumeBatchLoadTask — resume a bulk
import that Timestream paused (e.g. after transient S3 or throttling
failures).
Account-level binding invoked with no resource argument; keyed by TaskId.
Provide Timestream.ResumeBatchLoadTaskHttp on the Function to implement
the binding.
ResumeBatchLoadTask: Batch Loading
Section titled “ResumeBatchLoadTask: Batch Loading”// init — account-level binding, no resource argumentconst resumeBatchLoadTask = yield* Timestream.ResumeBatchLoadTask();
// runtimeyield* resumeBatchLoadTask({ TaskId: task.TaskId });ScheduledQuery
Section titled “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.
ScheduledQuery: Creating Scheduled Queries
Section titled “ScheduledQuery: Creating Scheduled Queries”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",});Source:
src/AWS/Timestream/Table.ts
An Amazon Timestream for LiveAnalytics table — a time-series store inside a
Database.
Table owns the table’s lifecycle and its mutable configuration: memory and
magnetic store retention, magnetic store write behavior, and tags. A table
name is auto-generated from the app, stage, and logical ID unless you provide
one.
Table: Creating Tables
Section titled “Table: Creating Tables”Basic Table
import * as Timestream from "alchemy/AWS/Timestream";
const database = yield* Timestream.Database("Metrics");const table = yield* Timestream.Table("Cpu", { databaseName: database.databaseName,});Table with Retention Tuning
const table = yield* Timestream.Table("Cpu", { databaseName: database.databaseName, retentionProperties: { memoryStoreRetention: "24 hours", magneticStoreRetention: "365 days", },});Table: Writing Points
Section titled “Table: Writing Points”// initconst writeRecords = yield* Timestream.WriteRecords(table);
return { fetch: Effect.gen(function* () { // runtime yield* writeRecords({ Records: [ { Dimensions: [{ Name: "host", Value: "web-1" }], MeasureName: "cpu", MeasureValue: "42.0", MeasureValueType: "DOUBLE", Time: `${Date.now()}`, TimeUnit: "MILLISECONDS", }, ], }); return HttpServerResponse.text("ok"); }),};WriteRecords
Section titled “WriteRecords”Source:
src/AWS/Timestream/WriteRecords.ts
Runtime binding for timestream-write:WriteRecords — ingest time-series
records into a Timestream Table.
Bind the operation to a table inside a function runtime to get a callable
with DatabaseName and TableName injected automatically; you only supply
the Records (and optional CommonAttributes). For high-volume streaming
ingestion prefer the batching RecordsSink.
Provide Timestream.WriteRecordsHttp on the Function to implement the
binding.
WriteRecords: Writing Records
Section titled “WriteRecords: Writing Records”// init — bind the operation to the tableconst writeRecords = yield* Timestream.WriteRecords(table);
// runtime — ingest a recordconst result = yield* writeRecords({ Records: [ { Dimensions: [{ Name: "host", Value: "web-1" }], MeasureName: "cpu", MeasureValue: "42.5", MeasureValueType: "DOUBLE", Time: `${Date.now()}`, TimeUnit: "MILLISECONDS", }, ],});// result.RecordsIngested reports how many records landed