ScheduledQuery class

Resource for managing an AWS Timestream Query Scheduled Query.

Example Usage

Basic Usage

Before creating a scheduled query, you must have a source database and table with ingested data. Below is a multi-step example, providing an opportunity for data ingestion.

If your infrastructure is already set up—including the source database and table with data, results database and table, error report S3 bucket, SNS topic, and IAM role—you can create a scheduled query as follows:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.timestreamquery.ScheduledQuery("example", {
    errorReportConfiguration: {
        s3Configuration: {
            bucketName: exampleAwsS3Bucket.bucket,
        },
    },
    notificationConfiguration: {
        snsConfiguration: {
            topicArn: exampleAwsSnsTopic.arn,
        },
    },
    scheduleConfiguration: {
        scheduleExpression: "rate(1 hour)",
    },
    targetConfiguration: {
        timestreamConfiguration: {
            multiMeasureMappings: {
                multiMeasureAttributeMappings: [
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "avg_cpu_utilization",
                    },
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "p90_cpu_utilization",
                    },
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "p95_cpu_utilization",
                    },
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "p99_cpu_utilization",
                    },
                ],
                targetMultiMeasureName: "multi-metrics",
            },
            dimensionMappings: [
                {
                    dimensionValueType: "VARCHAR",
                    name: "az",
                },
                {
                    dimensionValueType: "VARCHAR",
                    name: "region",
                },
                {
                    dimensionValueType: "VARCHAR",
                    name: "hostname",
                },
            ],
            databaseName: results.databaseName,
            tableName: resultsAwsTimestreamwriteTable.tableName,
            timeColumn: "binned_timestamp",
        },
    },
    executionRoleArn: exampleAwsIamRole.arn,
    name: exampleAwsTimestreamwriteTable.tableName,
    queryString: `SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
`,
});
import pulumi
import pulumi_aws as aws

example = aws.timestreamquery.ScheduledQuery("example",
    error_report_configuration={
        "s3_configuration": {
            "bucket_name": example_aws_s3_bucket["bucket"],
        },
    },
    notification_configuration={
        "sns_configuration": {
            "topic_arn": example_aws_sns_topic["arn"],
        },
    },
    schedule_configuration={
        "schedule_expression": "rate(1 hour)",
    },
    target_configuration={
        "timestream_configuration": {
            "multi_measure_mappings": {
                "multi_measure_attribute_mappings": [
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "avg_cpu_utilization",
                    },
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "p90_cpu_utilization",
                    },
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "p95_cpu_utilization",
                    },
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "p99_cpu_utilization",
                    },
                ],
                "target_multi_measure_name": "multi-metrics",
            },
            "dimension_mappings": [
                {
                    "dimension_value_type": "VARCHAR",
                    "name": "az",
                },
                {
                    "dimension_value_type": "VARCHAR",
                    "name": "region",
                },
                {
                    "dimension_value_type": "VARCHAR",
                    "name": "hostname",
                },
            ],
            "database_name": results["databaseName"],
            "table_name": results_aws_timestreamwrite_table["tableName"],
            "time_column": "binned_timestamp",
        },
    },
    execution_role_arn=example_aws_iam_role["arn"],
    name=example_aws_timestreamwrite_table["tableName"],
    query_string="""SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
""")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.TimestreamQuery.ScheduledQuery("example", new()
    {
        ErrorReportConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryErrorReportConfigurationArgs
        {
            S3Configuration = new Aws.TimestreamQuery.Inputs.ScheduledQueryErrorReportConfigurationS3ConfigurationArgs
            {
                BucketName = exampleAwsS3Bucket.Bucket,
            },
        },
        NotificationConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryNotificationConfigurationArgs
        {
            SnsConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryNotificationConfigurationSnsConfigurationArgs
            {
                TopicArn = exampleAwsSnsTopic.Arn,
            },
        },
        ScheduleConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryScheduleConfigurationArgs
        {
            ScheduleExpression = "rate(1 hour)",
        },
        TargetConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationArgs
        {
            TimestreamConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationArgs
            {
                MultiMeasureMappings = new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs
                {
                    MultiMeasureAttributeMappings = new[]
                    {
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "avg_cpu_utilization",
                        },
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "p90_cpu_utilization",
                        },
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "p95_cpu_utilization",
                        },
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "p99_cpu_utilization",
                        },
                    },
                    TargetMultiMeasureName = "multi-metrics",
                },
                DimensionMappings = new[]
                {
                    new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs
                    {
                        DimensionValueType = "VARCHAR",
                        Name = "az",
                    },
                    new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs
                    {
                        DimensionValueType = "VARCHAR",
                        Name = "region",
                    },
                    new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs
                    {
                        DimensionValueType = "VARCHAR",
                        Name = "hostname",
                    },
                },
                DatabaseName = results.DatabaseName,
                TableName = resultsAwsTimestreamwriteTable.TableName,
                TimeColumn = "binned_timestamp",
            },
        },
        ExecutionRoleArn = exampleAwsIamRole.Arn,
        Name = exampleAwsTimestreamwriteTable.TableName,
        QueryString = @"SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
",
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/timestreamquery"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := timestreamquery.NewScheduledQuery(ctx, "example", &timestreamquery.ScheduledQueryArgs{
			ErrorReportConfiguration: &timestreamquery.ScheduledQueryErrorReportConfigurationArgs{
				S3Configuration: &timestreamquery.ScheduledQueryErrorReportConfigurationS3ConfigurationArgs{
					BucketName: pulumi.Any(exampleAwsS3Bucket.Bucket),
				},
			},
			NotificationConfiguration: &timestreamquery.ScheduledQueryNotificationConfigurationArgs{
				SnsConfiguration: &timestreamquery.ScheduledQueryNotificationConfigurationSnsConfigurationArgs{
					TopicArn: pulumi.Any(exampleAwsSnsTopic.Arn),
				},
			},
			ScheduleConfiguration: &timestreamquery.ScheduledQueryScheduleConfigurationArgs{
				ScheduleExpression: pulumi.String("rate(1 hour)"),
			},
			TargetConfiguration: &timestreamquery.ScheduledQueryTargetConfigurationArgs{
				TimestreamConfiguration: &timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationArgs{
					MultiMeasureMappings: &timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs{
						MultiMeasureAttributeMappings: timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArray{
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("avg_cpu_utilization"),
							},
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("p90_cpu_utilization"),
							},
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("p95_cpu_utilization"),
							},
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("p99_cpu_utilization"),
							},
						},
						TargetMultiMeasureName: pulumi.String("multi-metrics"),
					},
					DimensionMappings: timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArray{
						&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs{
							DimensionValueType: pulumi.String("VARCHAR"),
							Name:               pulumi.String("az"),
						},
						&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs{
							DimensionValueType: pulumi.String("VARCHAR"),
							Name:               pulumi.String("region"),
						},
						&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs{
							DimensionValueType: pulumi.String("VARCHAR"),
							Name:               pulumi.String("hostname"),
						},
					},
					DatabaseName: pulumi.Any(results.DatabaseName),
					TableName:    pulumi.Any(resultsAwsTimestreamwriteTable.TableName),
					TimeColumn:   pulumi.String("binned_timestamp"),
				},
			},
			ExecutionRoleArn: pulumi.Any(exampleAwsIamRole.Arn),
			Name:             pulumi.Any(exampleAwsTimestreamwriteTable.TableName),
			QueryString: pulumi.String(`SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
`),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_timestreamquery_scheduledquery" "example" {
  error_report_configuration = {
    s3_configuration = {
      bucket_name = exampleAwsS3Bucket.bucket
    }
  }
  notification_configuration = {
    sns_configuration = {
      topic_arn = exampleAwsSnsTopic.arn
    }
  }
  schedule_configuration = {
    schedule_expression = "rate(1 hour)"
  }
  target_configuration = {
    timestream_configuration = {
      multi_measure_mappings = {
        multi_measure_attribute_mappings = [{
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "avg_cpu_utilization"
          }, {
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "p90_cpu_utilization"
          }, {
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "p95_cpu_utilization"
          }, {
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "p99_cpu_utilization"
        }]
        target_multi_measure_name = "multi-metrics"
      }
      dimension_mappings = [{
        "dimensionValueType" = "VARCHAR"
        "name"               = "az"
        }, {
        "dimensionValueType" = "VARCHAR"
        "name"               = "region"
        }, {
        "dimensionValueType" = "VARCHAR"
        "name"               = "hostname"
      }]
      database_name = results.databaseName
      table_name    = resultsAwsTimestreamwriteTable.tableName
      time_column   = "binned_timestamp"
    }
  }
  execution_role_arn = exampleAwsIamRole.arn
  name               = exampleAwsTimestreamwriteTable.tableName
  query_string       = "SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,\n\\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,\n\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,\n\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,\n\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization\nFROM exampledatabase.exampletable\nWHERE measure_name = 'metrics' AND time > ago(2h)\nGROUP BY region, hostname, az, BIN(time, 15s)\nORDER BY binned_timestamp ASC\nLIMIT 5\n"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.timestreamquery.ScheduledQuery;
import com.pulumi.aws.timestreamquery.ScheduledQueryArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryErrorReportConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryErrorReportConfigurationS3ConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryNotificationConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryNotificationConfigurationSnsConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryScheduleConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new ScheduledQuery("example", ScheduledQueryArgs.builder()
            .errorReportConfiguration(ScheduledQueryErrorReportConfigurationArgs.builder()
                .s3Configuration(ScheduledQueryErrorReportConfigurationS3ConfigurationArgs.builder()
                    .bucketName(exampleAwsS3Bucket.bucket())
                    .build())
                .build())
            .notificationConfiguration(ScheduledQueryNotificationConfigurationArgs.builder()
                .snsConfiguration(ScheduledQueryNotificationConfigurationSnsConfigurationArgs.builder()
                    .topicArn(exampleAwsSnsTopic.arn())
                    .build())
                .build())
            .scheduleConfiguration(ScheduledQueryScheduleConfigurationArgs.builder()
                .scheduleExpression("rate(1 hour)")
                .build())
            .targetConfiguration(ScheduledQueryTargetConfigurationArgs.builder()
                .timestreamConfiguration(ScheduledQueryTargetConfigurationTimestreamConfigurationArgs.builder()
                    .multiMeasureMappings(ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs.builder()
                        .multiMeasureAttributeMappings(
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("avg_cpu_utilization")
                                .build(),
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("p90_cpu_utilization")
                                .build(),
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("p95_cpu_utilization")
                                .build(),
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("p99_cpu_utilization")
                                .build())
                        .targetMultiMeasureName("multi-metrics")
                        .build())
                    .dimensionMappings(
                        ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs.builder()
                            .dimensionValueType("VARCHAR")
                            .name("az")
                            .build(),
                        ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs.builder()
                            .dimensionValueType("VARCHAR")
                            .name("region")
                            .build(),
                        ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs.builder()
                            .dimensionValueType("VARCHAR")
                            .name("hostname")
                            .build())
                    .databaseName(results.databaseName())
                    .tableName(resultsAwsTimestreamwriteTable.tableName())
                    .timeColumn("binned_timestamp")
                    .build())
                .build())
            .executionRoleArn(exampleAwsIamRole.arn())
            .name(exampleAwsTimestreamwriteTable.tableName())
            .queryString("""
SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
            """)
            .build());

    }
}
resources:
  example:
    type: aws:timestreamquery:ScheduledQuery
    properties:
      errorReportConfiguration:
        s3Configuration:
          bucketName: ${exampleAwsS3Bucket.bucket}
      notificationConfiguration:
        snsConfiguration:
          topicArn: ${exampleAwsSnsTopic.arn}
      scheduleConfiguration:
        scheduleExpression: rate(1 hour)
      targetConfiguration:
        timestreamConfiguration:
          multiMeasureMappings:
            multiMeasureAttributeMappings:
              - measureValueType: DOUBLE
                sourceColumn: avg_cpu_utilization
              - measureValueType: DOUBLE
                sourceColumn: p90_cpu_utilization
              - measureValueType: DOUBLE
                sourceColumn: p95_cpu_utilization
              - measureValueType: DOUBLE
                sourceColumn: p99_cpu_utilization
            targetMultiMeasureName: multi-metrics
          dimensionMappings:
            - dimensionValueType: VARCHAR
              name: az
            - dimensionValueType: VARCHAR
              name: region
            - dimensionValueType: VARCHAR
              name: hostname
          databaseName: ${results.databaseName}
          tableName: ${resultsAwsTimestreamwriteTable.tableName}
          timeColumn: binned_timestamp
      executionRoleArn: ${exampleAwsIamRole.arn}
      name: ${exampleAwsTimestreamwriteTable.tableName}
      queryString: |
        SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
        \tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
        \tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
        \tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
        \tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
        FROM exampledatabase.exampletable
        WHERE measure_name = 'metrics' AND time > ago(2h)
        GROUP BY region, hostname, az, BIN(time, 15s)
        ORDER BY binned_timestamp ASC
        LIMIT 5

Multi-step Example

To ingest data before creating a scheduled query, this example provides multiple steps:

  1. Create the prerequisite infrastructure
  2. Ingest data
  3. Create the scheduled query

Step 1. Create the prerequisite infrastructure

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const test = new aws.s3.Bucket("test", {
    bucket: "example",
    forceDestroy: true,
});
const testTopic = new aws.sns.Topic("test", {name: "example"});
const testQueue = new aws.sqs.Queue("test", {
    name: "example",
    sqsManagedSseEnabled: true,
});
const testTopicSubscription = new aws.sns.TopicSubscription("test", {
    topic: testTopic.arn,
    protocol: "sqs",
    endpoint: testQueue.arn,
});
const testQueuePolicy = new aws.sqs.QueuePolicy("test", {
    queueUrl: testQueue.id,
    policy: pulumi.jsonStringify({
        Version: "2012-10-17",
        Statement: [{
            Effect: "Allow",
            Principal: {
                AWS: "*",
            },
            Action: ["sqs:SendMessage"],
            Resource: testQueue.arn,
            Condition: {
                ArnEquals: {
                    "aws:SourceArn": testTopic.arn,
                },
            },
        }],
    }),
});
const testRole = new aws.iam.Role("test", {
    name: "example",
    assumeRolePolicy: JSON.stringify({
        Version: "2012-10-17",
        Statement: [{
            Effect: "Allow",
            Principal: {
                Service: "timestream.amazonaws.com",
            },
            Action: "sts:AssumeRole",
        }],
    }),
    tags: {
        Name: "example",
    },
});
const testRolePolicy = new aws.iam.RolePolicy("test", {
    name: "example",
    role: testRole.id,
    policy: JSON.stringify({
        Version: "2012-10-17",
        Statement: [{
            Action: [
                "kms:Decrypt",
                "sns:Publish",
                "timestream:describeEndpoints",
                "timestream:Select",
                "timestream:SelectValues",
                "timestream:WriteRecords",
                "s3:PutObject",
            ],
            Resource: "*",
            Effect: "Allow",
        }],
    }),
});
const testDatabase = new aws.timestreamwrite.Database("test", {databaseName: "exampledatabase"});
const testTable = new aws.timestreamwrite.Table("test", {
    magneticStoreWriteProperties: {
        enableMagneticStoreWrites: true,
    },
    retentionProperties: {
        magneticStoreRetentionPeriodInDays: 1,
        memoryStoreRetentionPeriodInHours: 1,
    },
    databaseName: testDatabase.databaseName,
    tableName: "exampletable",
});
const results = new aws.timestreamwrite.Database("results", {databaseName: "exampledatabase-results"});
const resultsTable = new aws.timestreamwrite.Table("results", {
    magneticStoreWriteProperties: {
        enableMagneticStoreWrites: true,
    },
    retentionProperties: {
        magneticStoreRetentionPeriodInDays: 1,
        memoryStoreRetentionPeriodInHours: 1,
    },
    databaseName: results.databaseName,
    tableName: "exampletable-results",
});
import pulumi
import json
import pulumi_aws as aws

test = aws.s3.Bucket("test",
    bucket="example",
    force_destroy=True)
test_topic = aws.sns.Topic("test", name="example")
test_queue = aws.sqs.Queue("test",
    name="example",
    sqs_managed_sse_enabled=True)
test_topic_subscription = aws.sns.TopicSubscription("test",
    topic=test_topic.arn,
    protocol="sqs",
    endpoint=test_queue.arn)
test_queue_policy = aws.sqs.QueuePolicy("test",
    queue_url=test_queue.id,
    policy=pulumi.Output.json_dumps({
        "Version": "2012-10-17",
        "Statement": [{
            "Effect": "Allow",
            "Principal": {
                "AWS": "*",
            },
            "Action": ["sqs:SendMessage"],
            "Resource": test_queue.arn,
            "Condition": {
                "ArnEquals": {
                    "aws:SourceArn": test_topic.arn,
                },
            },
        }],
    }))
test_role = aws.iam.Role("test",
    name="example",
    assume_role_policy=json.dumps({
        "Version": "2012-10-17",
        "Statement": [{
            "Effect": "Allow",
            "Principal": {
                "Service": "timestream.amazonaws.com",
            },
            "Action": "sts:AssumeRole",
        }],
    }),
    tags={
        "Name": "example",
    })
test_role_policy = aws.iam.RolePolicy("test",
    name="example",
    role=test_role.id,
    policy=json.dumps({
        "Version": "2012-10-17",
        "Statement": [{
            "Action": [
                "kms:Decrypt",
                "sns:Publish",
                "timestream:describeEndpoints",
                "timestream:Select",
                "timestream:SelectValues",
                "timestream:WriteRecords",
                "s3:PutObject",
            ],
            "Resource": "*",
            "Effect": "Allow",
        }],
    }))
test_database = aws.timestreamwrite.Database("test", database_name="exampledatabase")
test_table = aws.timestreamwrite.Table("test",
    magnetic_store_write_properties={
        "enable_magnetic_store_writes": True,
    },
    retention_properties={
        "magnetic_store_retention_period_in_days": 1,
        "memory_store_retention_period_in_hours": 1,
    },
    database_name=test_database.database_name,
    table_name="exampletable")
results = aws.timestreamwrite.Database("results", database_name="exampledatabase-results")
results_table = aws.timestreamwrite.Table("results",
    magnetic_store_write_properties={
        "enable_magnetic_store_writes": True,
    },
    retention_properties={
        "magnetic_store_retention_period_in_days": 1,
        "memory_store_retention_period_in_hours": 1,
    },
    database_name=results.database_name,
    table_name="exampletable-results")
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var test = new Aws.S3.Bucket("test", new()
    {
        BucketName = "example",
        ForceDestroy = true,
    });

    var testTopic = new Aws.Sns.Topic("test", new()
    {
        Name = "example",
    });

    var testQueue = new Aws.Sqs.Queue("test", new()
    {
        Name = "example",
        SqsManagedSseEnabled = true,
    });

    var testTopicSubscription = new Aws.Sns.TopicSubscription("test", new()
    {
        Topic = testTopic.Arn,
        Protocol = "sqs",
        Endpoint = testQueue.Arn,
    });

    var testQueuePolicy = new Aws.Sqs.QueuePolicy("test", new()
    {
        QueueUrl = testQueue.Id,
        Policy = Output.JsonSerialize(Output.Create(new Dictionary<string, object?>
        {
            ["Version"] = "2012-10-17",
            ["Statement"] = new[]
            {
                new Dictionary<string, object?>
                {
                    ["Effect"] = "Allow",
                    ["Principal"] = new Dictionary<string, object?>
                    {
                        ["AWS"] = "*",
                    },
                    ["Action"] = new[]
                    {
                        "sqs:SendMessage",
                    },
                    ["Resource"] = testQueue.Arn,
                    ["Condition"] = new Dictionary<string, object?>
                    {
                        ["ArnEquals"] = new Dictionary<string, object?>
                        {
                            ["aws:SourceArn"] = testTopic.Arn,
                        },
                    },
                },
            },
        })),
    });

    var testRole = new Aws.Iam.Role("test", new()
    {
        Name = "example",
        AssumeRolePolicy = JsonSerializer.Serialize(new Dictionary<string, object?>
        {
            ["Version"] = "2012-10-17",
            ["Statement"] = new[]
            {
                new Dictionary<string, object?>
                {
                    ["Effect"] = "Allow",
                    ["Principal"] = new Dictionary<string, object?>
                    {
                        ["Service"] = "timestream.amazonaws.com",
                    },
                    ["Action"] = "sts:AssumeRole",
                },
            },
        }),
        Tags =
        {
            { "Name", "example" },
        },
    });

    var testRolePolicy = new Aws.Iam.RolePolicy("test", new()
    {
        Name = "example",
        Role = testRole.Id,
        Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
        {
            ["Version"] = "2012-10-17",
            ["Statement"] = new[]
            {
                new Dictionary<string, object?>
                {
                    ["Action"] = new[]
                    {
                        "kms:Decrypt",
                        "sns:Publish",
                        "timestream:describeEndpoints",
                        "timestream:Select",
                        "timestream:SelectValues",
                        "timestream:WriteRecords",
                        "s3:PutObject",
                    },
                    ["Resource"] = "*",
                    ["Effect"] = "Allow",
                },
            },
        }),
    });

    var testDatabase = new Aws.TimestreamWrite.Database("test", new()
    {
        DatabaseName = "exampledatabase",
    });

    var testTable = new Aws.TimestreamWrite.Table("test", new()
    {
        MagneticStoreWriteProperties = new Aws.TimestreamWrite.Inputs.TableMagneticStoreWritePropertiesArgs
        {
            EnableMagneticStoreWrites = true,
        },
        RetentionProperties = new Aws.TimestreamWrite.Inputs.TableRetentionPropertiesArgs
        {
            MagneticStoreRetentionPeriodInDays = 1,
            MemoryStoreRetentionPeriodInHours = 1,
        },
        DatabaseName = testDatabase.DatabaseName,
        TableName = "exampletable",
    });

    var results = new Aws.TimestreamWrite.Database("results", new()
    {
        DatabaseName = "exampledatabase-results",
    });

    var resultsTable = new Aws.TimestreamWrite.Table("results", new()
    {
        MagneticStoreWriteProperties = new Aws.TimestreamWrite.Inputs.TableMagneticStoreWritePropertiesArgs
        {
            EnableMagneticStoreWrites = true,
        },
        RetentionProperties = new Aws.TimestreamWrite.Inputs.TableRetentionPropertiesArgs
        {
            MagneticStoreRetentionPeriodInDays = 1,
            MemoryStoreRetentionPeriodInHours = 1,
        },
        DatabaseName = results.DatabaseName,
        TableName = "exampletable-results",
    });

});
package main

import (
	"encoding/json"

	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/s3"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/sns"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/sqs"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/timestreamwrite"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := s3.NewBucket(ctx, "test", &s3.BucketArgs{
			Bucket:       pulumi.String("example"),
			ForceDestroy: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		testTopic, err := sns.NewTopic(ctx, "test", &sns.TopicArgs{
			Name: pulumi.String("example"),
		})
		if err != nil {
			return err
		}
		testQueue, err := sqs.NewQueue(ctx, "test", &sqs.QueueArgs{
			Name:                 pulumi.String("example"),
			SqsManagedSseEnabled: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		_, err = sns.NewTopicSubscription(ctx, "test", &sns.TopicSubscriptionArgs{
			Topic:    testTopic.Arn,
			Protocol: pulumi.String("sqs"),
			Endpoint: testQueue.Arn,
		})
		if err != nil {
			return err
		}
		_, err = sqs.NewQueuePolicy(ctx, "test", &sqs.QueuePolicyArgs{
			QueueUrl: testQueue.ID().ToIDOutput().ToStringOutput(),
			Policy: pulumi.All(testQueue.Arn, testTopic.Arn).ApplyT(func(_args []interface{}) (string, error) {
				testQueueArn := _args[0].(string)
				testTopicArn := _args[1].(string)
				var _zero string
				tmpJSON0, err := json.Marshal(map[string]interface{}{
					"Version": "2012-10-17",
					"Statement": []map[string]interface{}{
						map[string]interface{}{
							"Effect": "Allow",
							"Principal": map[string]string{
								"AWS": "*",
							},
							"Action": []string{
								"sqs:SendMessage",
							},
							"Resource": testQueueArn,
							"Condition": map[string]map[string]string{
								"ArnEquals": map[string]string{
									"aws:SourceArn": testTopicArn,
								},
							},
						},
					},
				})
				if err != nil {
					return _zero, err
				}
				json0 := string(tmpJSON0)
				return json0, nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		tmpJSON1, err := json.Marshal(map[string]interface{}{
			"Version": "2012-10-17",
			"Statement": []map[string]interface{}{
				map[string]interface{}{
					"Effect": "Allow",
					"Principal": map[string]string{
						"Service": "timestream.amazonaws.com",
					},
					"Action": "sts:AssumeRole",
				},
			},
		})
		if err != nil {
			return err
		}
		json1 := string(tmpJSON1)
		testRole, err := iam.NewRole(ctx, "test", &iam.RoleArgs{
			Name:             pulumi.String("example"),
			AssumeRolePolicy: pulumi.String(json1),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("example"),
			},
		})
		if err != nil {
			return err
		}
		tmpJSON2, err := json.Marshal(map[string]interface{}{
			"Version": "2012-10-17",
			"Statement": []map[string]interface{}{
				map[string]interface{}{
					"Action": []string{
						"kms:Decrypt",
						"sns:Publish",
						"timestream:describeEndpoints",
						"timestream:Select",
						"timestream:SelectValues",
						"timestream:WriteRecords",
						"s3:PutObject",
					},
					"Resource": "*",
					"Effect":   "Allow",
				},
			},
		})
		if err != nil {
			return err
		}
		json2 := string(tmpJSON2)
		_, err = iam.NewRolePolicy(ctx, "test", &iam.RolePolicyArgs{
			Name:   pulumi.String("example"),
			Role:   testRole.ID().ToIDOutput().ToStringOutput(),
			Policy: pulumi.String(json2),
		})
		if err != nil {
			return err
		}
		testDatabase, err := timestreamwrite.NewDatabase(ctx, "test", &timestreamwrite.DatabaseArgs{
			DatabaseName: pulumi.String("exampledatabase"),
		})
		if err != nil {
			return err
		}
		_, err = timestreamwrite.NewTable(ctx, "test", &timestreamwrite.TableArgs{
			MagneticStoreWriteProperties: &timestreamwrite.TableMagneticStoreWritePropertiesArgs{
				EnableMagneticStoreWrites: pulumi.Bool(true),
			},
			RetentionProperties: &timestreamwrite.TableRetentionPropertiesArgs{
				MagneticStoreRetentionPeriodInDays: pulumi.Int(1),
				MemoryStoreRetentionPeriodInHours:  pulumi.Int(1),
			},
			DatabaseName: testDatabase.DatabaseName,
			TableName:    pulumi.String("exampletable"),
		})
		if err != nil {
			return err
		}
		results, err := timestreamwrite.NewDatabase(ctx, "results", &timestreamwrite.DatabaseArgs{
			DatabaseName: pulumi.String("exampledatabase-results"),
		})
		if err != nil {
			return err
		}
		_, err = timestreamwrite.NewTable(ctx, "results", &timestreamwrite.TableArgs{
			MagneticStoreWriteProperties: &timestreamwrite.TableMagneticStoreWritePropertiesArgs{
				EnableMagneticStoreWrites: pulumi.Bool(true),
			},
			RetentionProperties: &timestreamwrite.TableRetentionPropertiesArgs{
				MagneticStoreRetentionPeriodInDays: pulumi.Int(1),
				MemoryStoreRetentionPeriodInHours:  pulumi.Int(1),
			},
			DatabaseName: results.DatabaseName,
			TableName:    pulumi.String("exampletable-results"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_s3_bucket" "test" {
  bucket        = "example"
  force_destroy = true
}
resource "aws_sns_topic" "test" {
  name = "example"
}
resource "aws_sqs_queue" "test" {
  name                    = "example"
  sqs_managed_sse_enabled = true
}
resource "aws_sns_topicsubscription" "test" {
  topic    = aws_sns_topic.test.arn
  protocol = "sqs"
  endpoint = aws_sqs_queue.test.arn
}
resource "aws_sqs_queuepolicy" "test" {
  queue_url = aws_sqs_queue.test.id
  policy = jsonencode({
    "Version" = "2012-10-17"
    "Statement" = [{
      "Effect" = "Allow"
      "Principal" = {
        "AWS" = "*"
      }
      "Action"   = ["sqs:SendMessage"]
      "Resource" = aws_sqs_queue.test.arn
      "Condition" = {
        "ArnEquals" = {
          "aws:SourceArn" = aws_sns_topic.test.arn
        }
      }
    }]
  })
}
resource "aws_iam_role" "test" {
  name = "example"
  assume_role_policy = jsonencode({
    "Version" = "2012-10-17"
    "Statement" = [{
      "Effect" = "Allow"
      "Principal" = {
        "Service" = "timestream.amazonaws.com"
      }
      "Action" = "sts:AssumeRole"
    }]
  })
  tags = {
    "Name" = "example"
  }
}
resource "aws_iam_rolepolicy" "test" {
  name = "example"
  role = aws_iam_role.test.id
  policy = jsonencode({
    "Version" = "2012-10-17"
    "Statement" = [{
      "Action"   = ["kms:Decrypt", "sns:Publish", "timestream:describeEndpoints", "timestream:Select", "timestream:SelectValues", "timestream:WriteRecords", "s3:PutObject"]
      "Resource" = "*"
      "Effect"   = "Allow"
    }]
  })
}
resource "aws_timestreamwrite_database" "test" {
  database_name = "exampledatabase"
}
resource "aws_timestreamwrite_table" "test" {
  magnetic_store_write_properties = {
    enable_magnetic_store_writes = true
  }
  retention_properties = {
    magnetic_store_retention_period_in_days = 1
    memory_store_retention_period_in_hours  = 1
  }
  database_name = aws_timestreamwrite_database.test.database_name
  table_name    = "exampletable"
}
resource "aws_timestreamwrite_database" "results" {
  database_name = "exampledatabase-results"
}
resource "aws_timestreamwrite_table" "results" {
  magnetic_store_write_properties = {
    enable_magnetic_store_writes = true
  }
  retention_properties = {
    magnetic_store_retention_period_in_days = 1
    memory_store_retention_period_in_hours  = 1
  }
  database_name = aws_timestreamwrite_database.results.database_name
  table_name    = "exampletable-results"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketArgs;
import com.pulumi.aws.sns.Topic;
import com.pulumi.aws.sns.TopicArgs;
import com.pulumi.aws.sqs.Queue;
import com.pulumi.aws.sqs.QueueArgs;
import com.pulumi.aws.sns.TopicSubscription;
import com.pulumi.aws.sns.TopicSubscriptionArgs;
import com.pulumi.aws.sqs.QueuePolicy;
import com.pulumi.aws.sqs.QueuePolicyArgs;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.iam.RolePolicy;
import com.pulumi.aws.iam.RolePolicyArgs;
import com.pulumi.aws.timestreamwrite.Database;
import com.pulumi.aws.timestreamwrite.DatabaseArgs;
import com.pulumi.aws.timestreamwrite.Table;
import com.pulumi.aws.timestreamwrite.TableArgs;
import com.pulumi.aws.timestreamwrite.inputs.TableMagneticStoreWritePropertiesArgs;
import com.pulumi.aws.timestreamwrite.inputs.TableRetentionPropertiesArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var test = new Bucket("test", BucketArgs.builder()
            .bucket("example")
            .forceDestroy(true)
            .build());

        var testTopic = new Topic("testTopic", TopicArgs.builder()
            .name("example")
            .build());

        var testQueue = new Queue("testQueue", QueueArgs.builder()
            .name("example")
            .sqsManagedSseEnabled(true)
            .build());

        var testTopicSubscription = new TopicSubscription("testTopicSubscription", TopicSubscriptionArgs.builder()
            .topic(testTopic.arn())
            .protocol("sqs")
            .endpoint(testQueue.arn())
            .build());

        var testQueuePolicy = new QueuePolicy("testQueuePolicy", QueuePolicyArgs.builder()
            .queueUrl(testQueue.id())
            .policy(Output.tuple(testQueue.arn(), testTopic.arn()).applyValue(values -> {
                var testQueueArn = values.t1;
                var testTopicArn = values.t2;
                return serializeJson(
                    jsonObject(
                        jsonProperty("Version", "2012-10-17"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Principal", jsonObject(
                                jsonProperty("AWS", "*")
                            )),
                            jsonProperty("Action", jsonArray("sqs:SendMessage")),
                            jsonProperty("Resource", testQueueArn),
                            jsonProperty("Condition", jsonObject(
                                jsonProperty("ArnEquals", jsonObject(
                                    jsonProperty("aws:SourceArn", testTopicArn)
                                ))
                            ))
                        )))
                    ));
            }))
            .build());

        var testRole = new Role("testRole", RoleArgs.builder()
            .name("example")
            .assumeRolePolicy(serializeJson(
                jsonObject(
                    jsonProperty("Version", "2012-10-17"),
                    jsonProperty("Statement", jsonArray(jsonObject(
                        jsonProperty("Effect", "Allow"),
                        jsonProperty("Principal", jsonObject(
                            jsonProperty("Service", "timestream.amazonaws.com")
                        )),
                        jsonProperty("Action", "sts:AssumeRole")
                    )))
                )))
            .tags(Map.of("Name", "example"))
            .build());

        var testRolePolicy = new RolePolicy("testRolePolicy", RolePolicyArgs.builder()
            .name("example")
            .role(testRole.id())
            .policy(serializeJson(
                jsonObject(
                    jsonProperty("Version", "2012-10-17"),
                    jsonProperty("Statement", jsonArray(jsonObject(
                        jsonProperty("Action", jsonArray(
                            "kms:Decrypt",
                            "sns:Publish",
                            "timestream:describeEndpoints",
                            "timestream:Select",
                            "timestream:SelectValues",
                            "timestream:WriteRecords",
                            "s3:PutObject"
                        )),
                        jsonProperty("Resource", "*"),
                        jsonProperty("Effect", "Allow")
                    )))
                )))
            .build());

        var testDatabase = new Database("testDatabase", DatabaseArgs.builder()
            .databaseName("exampledatabase")
            .build());

        var testTable = new Table("testTable", TableArgs.builder()
            .magneticStoreWriteProperties(TableMagneticStoreWritePropertiesArgs.builder()
                .enableMagneticStoreWrites(true)
                .build())
            .retentionProperties(TableRetentionPropertiesArgs.builder()
                .magneticStoreRetentionPeriodInDays(1)
                .memoryStoreRetentionPeriodInHours(1)
                .build())
            .databaseName(testDatabase.databaseName())
            .tableName("exampletable")
            .build());

        var results = new Database("results", DatabaseArgs.builder()
            .databaseName("exampledatabase-results")
            .build());

        var resultsTable = new Table("resultsTable", TableArgs.builder()
            .magneticStoreWriteProperties(TableMagneticStoreWritePropertiesArgs.builder()
                .enableMagneticStoreWrites(true)
                .build())
            .retentionProperties(TableRetentionPropertiesArgs.builder()
                .magneticStoreRetentionPeriodInDays(1)
                .memoryStoreRetentionPeriodInHours(1)
                .build())
            .databaseName(results.databaseName())
            .tableName("exampletable-results")
            .build());

    }
}
resources:
  test:
    type: aws:s3:Bucket
    properties:
      bucket: example
      forceDestroy: true
  testTopic:
    type: aws:sns:Topic
    name: test
    properties:
      name: example
  testQueue:
    type: aws:sqs:Queue
    name: test
    properties:
      name: example
      sqsManagedSseEnabled: true
  testTopicSubscription:
    type: aws:sns:TopicSubscription
    name: test
    properties:
      topic: ${testTopic.arn}
      protocol: sqs
      endpoint: ${testQueue.arn}
  testQueuePolicy:
    type: aws:sqs:QueuePolicy
    name: test
    properties:
      queueUrl: ${testQueue.id}
      policy:
        fn::toJSON:
          Version: 2012-10-17
          Statement:
            - Effect: Allow
              Principal:
                AWS: '*'
              Action:
                - sqs:SendMessage
              Resource: ${testQueue.arn}
              Condition:
                ArnEquals:
                  aws:SourceArn: ${testTopic.arn}
  testRole:
    type: aws:iam:Role
    name: test
    properties:
      name: example
      assumeRolePolicy:
        fn::toJSON:
          Version: 2012-10-17
          Statement:
            - Effect: Allow
              Principal:
                Service: timestream.amazonaws.com
              Action: sts:AssumeRole
      tags:
        Name: example
  testRolePolicy:
    type: aws:iam:RolePolicy
    name: test
    properties:
      name: example
      role: ${testRole.id}
      policy:
        fn::toJSON:
          Version: 2012-10-17
          Statement:
            - Action:
                - kms:Decrypt
                - sns:Publish
                - timestream:describeEndpoints
                - timestream:Select
                - timestream:SelectValues
                - timestream:WriteRecords
                - s3:PutObject
              Resource: '*'
              Effect: Allow
  testDatabase:
    type: aws:timestreamwrite:Database
    name: test
    properties:
      databaseName: exampledatabase
  testTable:
    type: aws:timestreamwrite:Table
    name: test
    properties:
      magneticStoreWriteProperties:
        enableMagneticStoreWrites: true
      retentionProperties:
        magneticStoreRetentionPeriodInDays: 1
        memoryStoreRetentionPeriodInHours: 1
      databaseName: ${testDatabase.databaseName}
      tableName: exampletable
  results:
    type: aws:timestreamwrite:Database
    properties:
      databaseName: exampledatabase-results
  resultsTable:
    type: aws:timestreamwrite:Table
    name: results
    properties:
      magneticStoreWriteProperties:
        enableMagneticStoreWrites: true
      retentionProperties:
        magneticStoreRetentionPeriodInDays: 1
        memoryStoreRetentionPeriodInHours: 1
      databaseName: ${results.databaseName}
      tableName: exampletable-results

Step 2. Ingest data

This is done with Amazon Timestream Write WriteRecords.

Step 3. Create the scheduled query

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.timestreamquery.ScheduledQuery("example", {
    errorReportConfiguration: {
        s3Configuration: {
            bucketName: exampleAwsS3Bucket.bucket,
        },
    },
    notificationConfiguration: {
        snsConfiguration: {
            topicArn: exampleAwsSnsTopic.arn,
        },
    },
    scheduleConfiguration: {
        scheduleExpression: "rate(1 hour)",
    },
    targetConfiguration: {
        timestreamConfiguration: {
            multiMeasureMappings: {
                multiMeasureAttributeMappings: [
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "avg_cpu_utilization",
                    },
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "p90_cpu_utilization",
                    },
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "p95_cpu_utilization",
                    },
                    {
                        measureValueType: "DOUBLE",
                        sourceColumn: "p99_cpu_utilization",
                    },
                ],
                targetMultiMeasureName: "multi-metrics",
            },
            dimensionMappings: [
                {
                    dimensionValueType: "VARCHAR",
                    name: "az",
                },
                {
                    dimensionValueType: "VARCHAR",
                    name: "region",
                },
                {
                    dimensionValueType: "VARCHAR",
                    name: "hostname",
                },
            ],
            databaseName: results.databaseName,
            tableName: resultsAwsTimestreamwriteTable.tableName,
            timeColumn: "binned_timestamp",
        },
    },
    executionRoleArn: exampleAwsIamRole.arn,
    name: exampleAwsTimestreamwriteTable.tableName,
    queryString: `SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
`,
});
import pulumi
import pulumi_aws as aws

example = aws.timestreamquery.ScheduledQuery("example",
    error_report_configuration={
        "s3_configuration": {
            "bucket_name": example_aws_s3_bucket["bucket"],
        },
    },
    notification_configuration={
        "sns_configuration": {
            "topic_arn": example_aws_sns_topic["arn"],
        },
    },
    schedule_configuration={
        "schedule_expression": "rate(1 hour)",
    },
    target_configuration={
        "timestream_configuration": {
            "multi_measure_mappings": {
                "multi_measure_attribute_mappings": [
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "avg_cpu_utilization",
                    },
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "p90_cpu_utilization",
                    },
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "p95_cpu_utilization",
                    },
                    {
                        "measure_value_type": "DOUBLE",
                        "source_column": "p99_cpu_utilization",
                    },
                ],
                "target_multi_measure_name": "multi-metrics",
            },
            "dimension_mappings": [
                {
                    "dimension_value_type": "VARCHAR",
                    "name": "az",
                },
                {
                    "dimension_value_type": "VARCHAR",
                    "name": "region",
                },
                {
                    "dimension_value_type": "VARCHAR",
                    "name": "hostname",
                },
            ],
            "database_name": results["databaseName"],
            "table_name": results_aws_timestreamwrite_table["tableName"],
            "time_column": "binned_timestamp",
        },
    },
    execution_role_arn=example_aws_iam_role["arn"],
    name=example_aws_timestreamwrite_table["tableName"],
    query_string="""SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
""")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.TimestreamQuery.ScheduledQuery("example", new()
    {
        ErrorReportConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryErrorReportConfigurationArgs
        {
            S3Configuration = new Aws.TimestreamQuery.Inputs.ScheduledQueryErrorReportConfigurationS3ConfigurationArgs
            {
                BucketName = exampleAwsS3Bucket.Bucket,
            },
        },
        NotificationConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryNotificationConfigurationArgs
        {
            SnsConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryNotificationConfigurationSnsConfigurationArgs
            {
                TopicArn = exampleAwsSnsTopic.Arn,
            },
        },
        ScheduleConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryScheduleConfigurationArgs
        {
            ScheduleExpression = "rate(1 hour)",
        },
        TargetConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationArgs
        {
            TimestreamConfiguration = new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationArgs
            {
                MultiMeasureMappings = new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs
                {
                    MultiMeasureAttributeMappings = new[]
                    {
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "avg_cpu_utilization",
                        },
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "p90_cpu_utilization",
                        },
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "p95_cpu_utilization",
                        },
                        new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs
                        {
                            MeasureValueType = "DOUBLE",
                            SourceColumn = "p99_cpu_utilization",
                        },
                    },
                    TargetMultiMeasureName = "multi-metrics",
                },
                DimensionMappings = new[]
                {
                    new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs
                    {
                        DimensionValueType = "VARCHAR",
                        Name = "az",
                    },
                    new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs
                    {
                        DimensionValueType = "VARCHAR",
                        Name = "region",
                    },
                    new Aws.TimestreamQuery.Inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs
                    {
                        DimensionValueType = "VARCHAR",
                        Name = "hostname",
                    },
                },
                DatabaseName = results.DatabaseName,
                TableName = resultsAwsTimestreamwriteTable.TableName,
                TimeColumn = "binned_timestamp",
            },
        },
        ExecutionRoleArn = exampleAwsIamRole.Arn,
        Name = exampleAwsTimestreamwriteTable.TableName,
        QueryString = @"SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
",
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/timestreamquery"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := timestreamquery.NewScheduledQuery(ctx, "example", &timestreamquery.ScheduledQueryArgs{
			ErrorReportConfiguration: &timestreamquery.ScheduledQueryErrorReportConfigurationArgs{
				S3Configuration: &timestreamquery.ScheduledQueryErrorReportConfigurationS3ConfigurationArgs{
					BucketName: pulumi.Any(exampleAwsS3Bucket.Bucket),
				},
			},
			NotificationConfiguration: &timestreamquery.ScheduledQueryNotificationConfigurationArgs{
				SnsConfiguration: &timestreamquery.ScheduledQueryNotificationConfigurationSnsConfigurationArgs{
					TopicArn: pulumi.Any(exampleAwsSnsTopic.Arn),
				},
			},
			ScheduleConfiguration: &timestreamquery.ScheduledQueryScheduleConfigurationArgs{
				ScheduleExpression: pulumi.String("rate(1 hour)"),
			},
			TargetConfiguration: &timestreamquery.ScheduledQueryTargetConfigurationArgs{
				TimestreamConfiguration: &timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationArgs{
					MultiMeasureMappings: &timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs{
						MultiMeasureAttributeMappings: timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArray{
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("avg_cpu_utilization"),
							},
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("p90_cpu_utilization"),
							},
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("p95_cpu_utilization"),
							},
							&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs{
								MeasureValueType: pulumi.String("DOUBLE"),
								SourceColumn:     pulumi.String("p99_cpu_utilization"),
							},
						},
						TargetMultiMeasureName: pulumi.String("multi-metrics"),
					},
					DimensionMappings: timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArray{
						&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs{
							DimensionValueType: pulumi.String("VARCHAR"),
							Name:               pulumi.String("az"),
						},
						&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs{
							DimensionValueType: pulumi.String("VARCHAR"),
							Name:               pulumi.String("region"),
						},
						&timestreamquery.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs{
							DimensionValueType: pulumi.String("VARCHAR"),
							Name:               pulumi.String("hostname"),
						},
					},
					DatabaseName: pulumi.Any(results.DatabaseName),
					TableName:    pulumi.Any(resultsAwsTimestreamwriteTable.TableName),
					TimeColumn:   pulumi.String("binned_timestamp"),
				},
			},
			ExecutionRoleArn: pulumi.Any(exampleAwsIamRole.Arn),
			Name:             pulumi.Any(exampleAwsTimestreamwriteTable.TableName),
			QueryString: pulumi.String(`SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
`),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_timestreamquery_scheduledquery" "example" {
  error_report_configuration = {
    s3_configuration = {
      bucket_name = exampleAwsS3Bucket.bucket
    }
  }
  notification_configuration = {
    sns_configuration = {
      topic_arn = exampleAwsSnsTopic.arn
    }
  }
  schedule_configuration = {
    schedule_expression = "rate(1 hour)"
  }
  target_configuration = {
    timestream_configuration = {
      multi_measure_mappings = {
        multi_measure_attribute_mappings = [{
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "avg_cpu_utilization"
          }, {
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "p90_cpu_utilization"
          }, {
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "p95_cpu_utilization"
          }, {
          "measureValueType" = "DOUBLE"
          "sourceColumn"     = "p99_cpu_utilization"
        }]
        target_multi_measure_name = "multi-metrics"
      }
      dimension_mappings = [{
        "dimensionValueType" = "VARCHAR"
        "name"               = "az"
        }, {
        "dimensionValueType" = "VARCHAR"
        "name"               = "region"
        }, {
        "dimensionValueType" = "VARCHAR"
        "name"               = "hostname"
      }]
      database_name = results.databaseName
      table_name    = resultsAwsTimestreamwriteTable.tableName
      time_column   = "binned_timestamp"
    }
  }
  execution_role_arn = exampleAwsIamRole.arn
  name               = exampleAwsTimestreamwriteTable.tableName
  query_string       = "SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,\n\\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,\n\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,\n\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,\n\\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization\nFROM exampledatabase.exampletable\nWHERE measure_name = 'metrics' AND time > ago(2h)\nGROUP BY region, hostname, az, BIN(time, 15s)\nORDER BY binned_timestamp ASC\nLIMIT 5\n"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.timestreamquery.ScheduledQuery;
import com.pulumi.aws.timestreamquery.ScheduledQueryArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryErrorReportConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryErrorReportConfigurationS3ConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryNotificationConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryNotificationConfigurationSnsConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryScheduleConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs;
import com.pulumi.aws.timestreamquery.inputs.ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new ScheduledQuery("example", ScheduledQueryArgs.builder()
            .errorReportConfiguration(ScheduledQueryErrorReportConfigurationArgs.builder()
                .s3Configuration(ScheduledQueryErrorReportConfigurationS3ConfigurationArgs.builder()
                    .bucketName(exampleAwsS3Bucket.bucket())
                    .build())
                .build())
            .notificationConfiguration(ScheduledQueryNotificationConfigurationArgs.builder()
                .snsConfiguration(ScheduledQueryNotificationConfigurationSnsConfigurationArgs.builder()
                    .topicArn(exampleAwsSnsTopic.arn())
                    .build())
                .build())
            .scheduleConfiguration(ScheduledQueryScheduleConfigurationArgs.builder()
                .scheduleExpression("rate(1 hour)")
                .build())
            .targetConfiguration(ScheduledQueryTargetConfigurationArgs.builder()
                .timestreamConfiguration(ScheduledQueryTargetConfigurationTimestreamConfigurationArgs.builder()
                    .multiMeasureMappings(ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsArgs.builder()
                        .multiMeasureAttributeMappings(
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("avg_cpu_utilization")
                                .build(),
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("p90_cpu_utilization")
                                .build(),
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("p95_cpu_utilization")
                                .build(),
                            ScheduledQueryTargetConfigurationTimestreamConfigurationMultiMeasureMappingsMultiMeasureAttributeMappingArgs.builder()
                                .measureValueType("DOUBLE")
                                .sourceColumn("p99_cpu_utilization")
                                .build())
                        .targetMultiMeasureName("multi-metrics")
                        .build())
                    .dimensionMappings(
                        ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs.builder()
                            .dimensionValueType("VARCHAR")
                            .name("az")
                            .build(),
                        ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs.builder()
                            .dimensionValueType("VARCHAR")
                            .name("region")
                            .build(),
                        ScheduledQueryTargetConfigurationTimestreamConfigurationDimensionMappingArgs.builder()
                            .dimensionValueType("VARCHAR")
                            .name("hostname")
                            .build())
                    .databaseName(results.databaseName())
                    .tableName(resultsAwsTimestreamwriteTable.tableName())
                    .timeColumn("binned_timestamp")
                    .build())
                .build())
            .executionRoleArn(exampleAwsIamRole.arn())
            .name(exampleAwsTimestreamwriteTable.tableName())
            .queryString("""
SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
\tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
\tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
FROM exampledatabase.exampletable
WHERE measure_name = 'metrics' AND time > ago(2h)
GROUP BY region, hostname, az, BIN(time, 15s)
ORDER BY binned_timestamp ASC
LIMIT 5
            """)
            .build());

    }
}
resources:
  example:
    type: aws:timestreamquery:ScheduledQuery
    properties:
      errorReportConfiguration:
        s3Configuration:
          bucketName: ${exampleAwsS3Bucket.bucket}
      notificationConfiguration:
        snsConfiguration:
          topicArn: ${exampleAwsSnsTopic.arn}
      scheduleConfiguration:
        scheduleExpression: rate(1 hour)
      targetConfiguration:
        timestreamConfiguration:
          multiMeasureMappings:
            multiMeasureAttributeMappings:
              - measureValueType: DOUBLE
                sourceColumn: avg_cpu_utilization
              - measureValueType: DOUBLE
                sourceColumn: p90_cpu_utilization
              - measureValueType: DOUBLE
                sourceColumn: p95_cpu_utilization
              - measureValueType: DOUBLE
                sourceColumn: p99_cpu_utilization
            targetMultiMeasureName: multi-metrics
          dimensionMappings:
            - dimensionValueType: VARCHAR
              name: az
            - dimensionValueType: VARCHAR
              name: region
            - dimensionValueType: VARCHAR
              name: hostname
          databaseName: ${results.databaseName}
          tableName: ${resultsAwsTimestreamwriteTable.tableName}
          timeColumn: binned_timestamp
      executionRoleArn: ${exampleAwsIamRole.arn}
      name: ${exampleAwsTimestreamwriteTable.tableName}
      queryString: |
        SELECT region, az, hostname, BIN(time, 15s) AS binned_timestamp,
        \tROUND(AVG(cpu_utilization), 2) AS avg_cpu_utilization,
        \tROUND(APPROX_PERCENTILE(cpu_utilization, 0.9), 2) AS p90_cpu_utilization,
        \tROUND(APPROX_PERCENTILE(cpu_utilization, 0.95), 2) AS p95_cpu_utilization,
        \tROUND(APPROX_PERCENTILE(cpu_utilization, 0.99), 2) AS p99_cpu_utilization
        FROM exampledatabase.exampletable
        WHERE measure_name = 'metrics' AND time > ago(2h)
        GROUP BY region, hostname, az, BIN(time, 15s)
        ORDER BY binned_timestamp ASC
        LIMIT 5

Import

Using pulumi import, import Timestream Query Scheduled Query using the arn. For example:

$ pulumi import aws:timestreamquery/scheduledQuery:ScheduledQuery example arn:aws:timestream:us-west-2:012345678901:scheduled-query/tf-acc-test-7774188528604787105-e13659544fe66c8d

Constructors

ScheduledQuery(String name, {ScheduledQueryArgs? args, CustomResourceOptions? options})
Creates a new ScheduledQuery. name The Pulumi resource name. args Arguments used to configure this ScheduledQuery. The set of arguments for ScheduledQuery. options Resource options controlling this resource's behavior.
ScheduledQuery.reference(String urn)
Creates a typed reference to an existing ScheduledQuery resource.

Properties

arn ↔ Output<String>
ARN of the Scheduled Query.
latefinal
childResources Set<Resource>
finalinherited
completionSources Map<String, IOutputCompletionSource>
latefinalinherited
creationTime ↔ Output<String>
Creation time for the scheduled query.
latefinal
errorReportConfiguration ↔ Output<ScheduledQueryErrorReportConfiguration>
Configuration block for error reporting configuration. See below.
latefinal
executionRoleArn ↔ Output<String>
ARN for the IAM role that Timestream will assume when running the scheduled query.
latefinal
hashCode int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference bool
Whether this instance represents a resource value returned over RPC.
finalinherited
kmsKeyId ↔ Output<String?>
Amazon KMS key used to encrypt the scheduled query resource, at-rest. If not specified, the scheduled query resource will be encrypted with a Timestream owned Amazon KMS key. To specify a KMS key, use the key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix the name with "alias/". If errorReportConfiguration uses SSE_KMS as the encryption type, the same kmsKeyId is used to encrypt the error report at rest.
latefinal
lastRunSummaries ↔ Output<List<ScheduledQueryLastRunSummary>?>
Runtime summary for the last scheduled query run.
latefinal
name ↔ Output<String>
Name of the scheduled query.
latefinal
nextInvocationTime ↔ Output<String>
Next time the scheduled query is scheduled to run.
latefinal
notificationConfiguration ↔ Output<ScheduledQueryNotificationConfiguration>
Configuration block for notification configuration for a scheduled query. A notification is sent by Timestream when a scheduled query is created, its state is updated, or when it is deleted. See below.
latefinal
previousInvocationTime ↔ Output<String>
Last time the scheduled query was run.
latefinal
queryString ↔ Output<String>
Query string to run. Parameter names can be specified in the query string using the @ character followed by an identifier. The named parameter @scheduled_runtime is reserved and can be used in the query to get the time at which the query is scheduled to run. The timestamp calculated according to the scheduleConfiguration parameter, will be the value of @scheduled_runtime paramater for each query run. For example, consider an instance of a scheduled query executing on 2021-12-01 00:00:00. For this instance, the @scheduled_runtime parameter is initialized to the timestamp 2021-12-01 00:00:00 when invoking the query.
latefinal
recentlyFailedRuns ↔ Output<List<ScheduledQueryRecentlyFailedRun>?>
Runtime summary for the last five failed scheduled query runs.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scheduleConfiguration ↔ Output<ScheduledQueryScheduleConfiguration>
Configuration block for schedule configuration for the query. See below.
latefinal
state ↔ Output<String>
State of the scheduled query, either ENABLED or DISABLED.
latefinal
tags ↔ Output<Map<String, String>?>
Map of tags assigned to the resource. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
Map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
targetConfiguration ↔ Output<ScheduledQueryTargetConfiguration>
Configuration block for writing the result of a query. See below.
latefinal
timeouts ↔ Output<ScheduledQueryTimeouts?>
latefinal
transformations List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() String
Returns this resource's logical name.
inherited
getResourceType() String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {ScheduledQueryState? state, CustomResourceOptions? options}) ScheduledQuery
Gets an existing ScheduledQuery resource's state with the given name and id.