{
  "typeName" : "AWS::Timestream::ScheduledQuery",
  "description" : "The AWS::Timestream::ScheduledQuery resource creates a Timestream Scheduled Query.",
  "sourceUrl" : "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-timestream.git",
  "definitions" : {
    "Arn" : {
      "description" : "Amazon Resource Name of the scheduled query that is generated upon creation.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 2048
    },
    "ScheduledQueryName" : {
      "description" : "The name of the scheduled query. Scheduled query names must be unique within each Region.",
      "type" : "string",
      "pattern" : "[a-zA-Z0-9_.-]+",
      "minLength" : 1,
      "maxLength" : 64
    },
    "QueryString" : {
      "description" : "The query string to run. Parameter names can be specified in the query string @ 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.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 262144
    },
    "ScheduleConfiguration" : {
      "description" : "Configuration for when the scheduled query is executed.",
      "type" : "object",
      "properties" : {
        "ScheduleExpression" : {
          "$ref" : "#/definitions/ScheduleExpression"
        }
      },
      "required" : [ "ScheduleExpression" ],
      "additionalProperties" : false
    },
    "NotificationConfiguration" : {
      "description" : "Notification configuration for the scheduled query. A notification is sent by Timestream when a query run finishes, when the state is updated or when you delete it.",
      "type" : "object",
      "properties" : {
        "SnsConfiguration" : {
          "$ref" : "#/definitions/SnsConfiguration"
        }
      },
      "required" : [ "SnsConfiguration" ],
      "additionalProperties" : false
    },
    "ClientToken" : {
      "description" : "Using a ClientToken makes the call to CreateScheduledQuery idempotent, in other words, making the same request repeatedly will produce the same result. Making multiple identical CreateScheduledQuery requests has the same effect as making a single request. If CreateScheduledQuery is called without a ClientToken, the Query SDK generates a ClientToken on your behalf. After 8 hours, any request with the same ClientToken is treated as a new request.",
      "type" : "string",
      "minLength" : 32,
      "maxLength" : 128
    },
    "ScheduledQueryExecutionRoleArn" : {
      "description" : "The ARN for the IAM role that Timestream will assume when running the scheduled query.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 2048
    },
    "TargetConfiguration" : {
      "description" : "Configuration of target store where scheduled query results are written to.",
      "type" : "object",
      "properties" : {
        "TimestreamConfiguration" : {
          "$ref" : "#/definitions/TimestreamConfiguration"
        }
      },
      "required" : [ "TimestreamConfiguration" ],
      "additionalProperties" : false
    },
    "ErrorReportConfiguration" : {
      "description" : "Configuration for error reporting. Error reports will be generated when a problem is encountered when writing the query results.",
      "type" : "object",
      "properties" : {
        "S3Configuration" : {
          "$ref" : "#/definitions/S3Configuration"
        }
      },
      "required" : [ "S3Configuration" ],
      "additionalProperties" : false
    },
    "KmsKeyId" : {
      "description" : "The Amazon KMS key used to encrypt the scheduled query resource, at-rest. If the Amazon KMS key is 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 encryption type, the same KmsKeyId is used to encrypt the error report at rest.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 2048
    },
    "Tags" : {
      "description" : "A list of key-value pairs to label the scheduled query.",
      "type" : "array",
      "insertionOrder" : false,
      "maxItems" : 200,
      "items" : {
        "$ref" : "#/definitions/Tag"
      }
    },
    "ScheduleExpression" : {
      "description" : "An expression that denotes when to trigger the scheduled query run. This can be a cron expression or a rate expression.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 256
    },
    "SnsConfiguration" : {
      "description" : "SNS configuration for notification upon scheduled query execution.",
      "type" : "object",
      "properties" : {
        "TopicArn" : {
          "$ref" : "#/definitions/TopicArn"
        }
      },
      "required" : [ "TopicArn" ],
      "additionalProperties" : false
    },
    "TopicArn" : {
      "description" : "SNS topic ARN that the scheduled query status notifications will be sent to.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 2048
    },
    "TimestreamConfiguration" : {
      "description" : "Configuration needed to write data into the Timestream database and table.",
      "type" : "object",
      "properties" : {
        "DatabaseName" : {
          "$ref" : "#/definitions/DatabaseName"
        },
        "TableName" : {
          "$ref" : "#/definitions/TableName"
        },
        "TimeColumn" : {
          "$ref" : "#/definitions/TimeColumn"
        },
        "DimensionMappings" : {
          "$ref" : "#/definitions/DimensionMappings"
        },
        "MultiMeasureMappings" : {
          "$ref" : "#/definitions/MultiMeasureMappings"
        },
        "MixedMeasureMappings" : {
          "$ref" : "#/definitions/MixedMeasureMappings"
        },
        "MeasureNameColumn" : {
          "$ref" : "#/definitions/MeasureNameColumn"
        }
      },
      "required" : [ "DatabaseName", "TableName", "TimeColumn", "DimensionMappings" ],
      "additionalProperties" : false
    },
    "DatabaseName" : {
      "description" : "Name of Timestream database to which the query result will be written.",
      "type" : "string"
    },
    "TableName" : {
      "description" : "Name of Timestream table that the query result will be written to. The table should be within the same database that is provided in Timestream configuration.",
      "type" : "string"
    },
    "TimeColumn" : {
      "description" : "Column from query result that should be used as the time column in destination table. Column type for this should be TIMESTAMP.",
      "type" : "string"
    },
    "DimensionMappings" : {
      "description" : "This is to allow mapping column(s) from the query result to the dimension in the destination table.",
      "type" : "array",
      "insertionOrder" : false,
      "items" : {
        "$ref" : "#/definitions/DimensionMapping"
      }
    },
    "DimensionMapping" : {
      "description" : "This type is used to map column(s) from the query result to a dimension in the destination table.",
      "type" : "object",
      "properties" : {
        "Name" : {
          "$ref" : "#/definitions/DimensionMappingName"
        },
        "DimensionValueType" : {
          "$ref" : "#/definitions/DimensionValueType"
        }
      },
      "required" : [ "Name", "DimensionValueType" ],
      "additionalProperties" : false
    },
    "DimensionMappingName" : {
      "description" : "Column name from query result.",
      "type" : "string"
    },
    "DimensionValueType" : {
      "description" : "Type for the dimension.",
      "type" : "string",
      "enum" : [ "VARCHAR" ]
    },
    "MultiMeasureMappings" : {
      "description" : "Only one of MixedMeasureMappings or MultiMeasureMappings is to be provided. MultiMeasureMappings can be used to ingest data as multi measures in the derived table.",
      "type" : "object",
      "properties" : {
        "TargetMultiMeasureName" : {
          "$ref" : "#/definitions/TargetMultiMeasureName"
        },
        "MultiMeasureAttributeMappings" : {
          "$ref" : "#/definitions/MultiMeasureAttributeMappingList"
        }
      },
      "required" : [ "MultiMeasureAttributeMappings" ],
      "additionalProperties" : false
    },
    "TargetMultiMeasureName" : {
      "description" : "Name of the target multi-measure in the derived table. Required if MeasureNameColumn is not provided. If MeasureNameColumn is provided then the value from that column will be used as the multi-measure name.",
      "type" : "string"
    },
    "MultiMeasureAttributeMappingList" : {
      "description" : "Required. Attribute mappings to be used for mapping query results to ingest data for multi-measure attributes.",
      "type" : "array",
      "insertionOrder" : false,
      "minItems" : 1,
      "items" : {
        "$ref" : "#/definitions/MultiMeasureAttributeMapping"
      }
    },
    "MultiMeasureAttributeMapping" : {
      "description" : "An attribute mapping to be used for mapping query results to ingest data for multi-measure attributes.",
      "type" : "object",
      "properties" : {
        "SourceColumn" : {
          "$ref" : "#/definitions/MultiMeasureAttributeMappingSourceColumn"
        },
        "MeasureValueType" : {
          "$ref" : "#/definitions/MultiMeasureAttributeMappingMeasureValueType"
        },
        "TargetMultiMeasureAttributeName" : {
          "$ref" : "#/definitions/TargetMultiMeasureAttributeName"
        }
      },
      "required" : [ "SourceColumn", "MeasureValueType" ],
      "additionalProperties" : false
    },
    "MultiMeasureAttributeMappingSourceColumn" : {
      "description" : "Source measure value column in the query result where the attribute value is to be read.",
      "type" : "string"
    },
    "MultiMeasureAttributeMappingMeasureValueType" : {
      "description" : "Value type of the measure value column to be read from the query result.",
      "type" : "string",
      "enum" : [ "BIGINT", "BOOLEAN", "DOUBLE", "VARCHAR", "TIMESTAMP" ]
    },
    "TargetMultiMeasureAttributeName" : {
      "description" : "Custom name to be used for attribute name in derived table. If not provided, source column name would be used.",
      "type" : "string"
    },
    "MixedMeasureMappings" : {
      "description" : "Specifies how to map measures to multi-measure records.",
      "type" : "array",
      "insertionOrder" : false,
      "minItems" : 1,
      "items" : {
        "$ref" : "#/definitions/MixedMeasureMapping"
      }
    },
    "MixedMeasureMapping" : {
      "description" : "MixedMeasureMappings are mappings that can be used to ingest data into a mixture of narrow and multi measures in the derived table.",
      "type" : "object",
      "properties" : {
        "MeasureName" : {
          "$ref" : "#/definitions/MixedMeasureMappingMeasureName"
        },
        "SourceColumn" : {
          "$ref" : "#/definitions/MixedMeasureMappingSourceColumn"
        },
        "TargetMeasureName" : {
          "$ref" : "#/definitions/MixedMeasureMappingTargetMeasureName"
        },
        "MeasureValueType" : {
          "$ref" : "#/definitions/MixedMeasureMappingMeasureValueType"
        },
        "MultiMeasureAttributeMappings" : {
          "$ref" : "#/definitions/MultiMeasureAttributeMappingList"
        }
      },
      "required" : [ "MeasureValueType" ],
      "additionalProperties" : false
    },
    "MixedMeasureMappingMeasureName" : {
      "description" : "Refers to the value of the measure name in a result row. This field is required if MeasureNameColumn is provided.",
      "type" : "string"
    },
    "MixedMeasureMappingSourceColumn" : {
      "description" : "This field refers to the source column from which the measure value is to be read for result materialization.",
      "type" : "string"
    },
    "MixedMeasureMappingTargetMeasureName" : {
      "description" : "Target measure name to be used. If not provided, the target measure name by default would be MeasureName if provided, or SourceColumn otherwise.",
      "type" : "string"
    },
    "MixedMeasureMappingMeasureValueType" : {
      "description" : "Type of the value that is to be read from SourceColumn. If the mapping is for MULTI, use MeasureValueType.MULTI.",
      "type" : "string",
      "enum" : [ "BIGINT", "BOOLEAN", "DOUBLE", "VARCHAR", "MULTI" ]
    },
    "MeasureNameColumn" : {
      "description" : "Name of the measure name column from the query result.",
      "type" : "string"
    },
    "S3Configuration" : {
      "description" : "Details on S3 location for error reports that result from running a query.",
      "type" : "object",
      "properties" : {
        "BucketName" : {
          "$ref" : "#/definitions/BucketName"
        },
        "ObjectKeyPrefix" : {
          "$ref" : "#/definitions/ObjectKeyPrefix"
        },
        "EncryptionOption" : {
          "$ref" : "#/definitions/EncryptionOption"
        }
      },
      "required" : [ "BucketName" ],
      "additionalProperties" : false
    },
    "BucketName" : {
      "description" : "Name of the S3 bucket under which error reports will be created.",
      "type" : "string",
      "minLength" : 3,
      "maxLength" : 63,
      "pattern" : "[a-z0-9][\\.\\-a-z0-9]{1,61}[a-z0-9]"
    },
    "ObjectKeyPrefix" : {
      "description" : "Prefix for error report keys.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 896,
      "pattern" : "[a-zA-Z0-9|!\\-_*'\\(\\)]([a-zA-Z0-9]|[!\\-_*'\\(\\)\\/.])+"
    },
    "EncryptionOption" : {
      "description" : "Encryption at rest options for the error reports. If no encryption option is specified, Timestream will choose SSE_S3 as default.",
      "type" : "string",
      "enum" : [ "SSE_S3", "SSE_KMS" ]
    },
    "Tag" : {
      "description" : "A key-value pair to label the scheduled query.",
      "type" : "object",
      "properties" : {
        "Key" : {
          "$ref" : "#/definitions/Key"
        },
        "Value" : {
          "$ref" : "#/definitions/Value"
        }
      },
      "required" : [ "Key", "Value" ],
      "additionalProperties" : false
    },
    "Key" : {
      "type" : "string",
      "description" : "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
      "minLength" : 1,
      "maxLength" : 128
    },
    "Value" : {
      "type" : "string",
      "description" : "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
      "minLength" : 0,
      "maxLength" : 256
    }
  },
  "properties" : {
    "Arn" : {
      "$ref" : "#/definitions/Arn"
    },
    "ScheduledQueryName" : {
      "$ref" : "#/definitions/ScheduledQueryName"
    },
    "QueryString" : {
      "$ref" : "#/definitions/QueryString"
    },
    "ScheduleConfiguration" : {
      "$ref" : "#/definitions/ScheduleConfiguration"
    },
    "NotificationConfiguration" : {
      "$ref" : "#/definitions/NotificationConfiguration"
    },
    "ClientToken" : {
      "$ref" : "#/definitions/ClientToken"
    },
    "ScheduledQueryExecutionRoleArn" : {
      "$ref" : "#/definitions/ScheduledQueryExecutionRoleArn"
    },
    "TargetConfiguration" : {
      "$ref" : "#/definitions/TargetConfiguration"
    },
    "ErrorReportConfiguration" : {
      "$ref" : "#/definitions/ErrorReportConfiguration"
    },
    "KmsKeyId" : {
      "$ref" : "#/definitions/KmsKeyId"
    },
    "SQName" : {
      "description" : "The name of the scheduled query. Scheduled query names must be unique within each Region.",
      "type" : "string"
    },
    "SQQueryString" : {
      "description" : "The query string to run. Parameter names can be specified in the query string @ 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.",
      "type" : "string"
    },
    "SQScheduleConfiguration" : {
      "description" : "Configuration for when the scheduled query is executed.",
      "type" : "string"
    },
    "SQNotificationConfiguration" : {
      "description" : "Notification configuration for the scheduled query. A notification is sent by Timestream when a query run finishes, when the state is updated or when you delete it.",
      "type" : "string"
    },
    "SQScheduledQueryExecutionRoleArn" : {
      "description" : "The ARN for the IAM role that Timestream will assume when running the scheduled query.",
      "type" : "string"
    },
    "SQTargetConfiguration" : {
      "description" : "Configuration of target store where scheduled query results are written to.",
      "type" : "string"
    },
    "SQErrorReportConfiguration" : {
      "description" : "Configuration for error reporting. Error reports will be generated when a problem is encountered when writing the query results.",
      "type" : "string"
    },
    "SQKmsKeyId" : {
      "description" : "The Amazon KMS key used to encrypt the scheduled query resource, at-rest. If the Amazon KMS key is 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 encryption type, the same KmsKeyId is used to encrypt the error report at rest.",
      "type" : "string"
    },
    "Tags" : {
      "$ref" : "#/definitions/Tags"
    }
  },
  "required" : [ "QueryString", "ScheduleConfiguration", "NotificationConfiguration", "ScheduledQueryExecutionRoleArn", "ErrorReportConfiguration" ],
  "additionalProperties" : false,
  "primaryIdentifier" : [ "/properties/Arn" ],
  "createOnlyProperties" : [ "/properties/ScheduledQueryName", "/properties/QueryString", "/properties/ScheduleConfiguration", "/properties/NotificationConfiguration", "/properties/ScheduledQueryExecutionRoleArn", "/properties/TargetConfiguration", "/properties/ErrorReportConfiguration", "/properties/KmsKeyId" ],
  "readOnlyProperties" : [ "/properties/Arn", "/properties/SQName", "/properties/SQQueryString", "/properties/SQScheduleConfiguration", "/properties/SQNotificationConfiguration", "/properties/SQScheduledQueryExecutionRoleArn", "/properties/SQTargetConfiguration", "/properties/SQErrorReportConfiguration", "/properties/SQKmsKeyId" ],
  "writeOnlyProperties" : [ "/properties/ClientToken" ],
  "tagging" : {
    "taggable" : true,
    "tagOnCreate" : true,
    "tagUpdatable" : true,
    "cloudFormationSystemTags" : true,
    "tagProperty" : "/properties/Tags",
    "permissions" : [ "timestream:TagResource", "timestream:ListTagsForResource", "timestream:UntagResource" ]
  },
  "handlers" : {
    "create" : {
      "permissions" : [ "timestream:CreateScheduledQuery", "timestream:DescribeEndpoints", "timestream:TagResource", "iam:PassRole", "kms:DescribeKey", "kms:GenerateDataKey" ]
    },
    "read" : {
      "permissions" : [ "timestream:DescribeScheduledQuery", "timestream:ListTagsForResource", "timestream:DescribeEndpoints", "kms:GenerateDataKey", "kms:Decrypt" ]
    },
    "update" : {
      "permissions" : [ "timestream:UpdateScheduledQuery", "timestream:TagResource", "timestream:UntagResource", "timestream:DescribeEndpoints" ]
    },
    "delete" : {
      "permissions" : [ "timestream:DeleteScheduledQuery", "timestream:DescribeScheduledQuery", "timestream:DescribeEndpoints" ]
    },
    "list" : {
      "permissions" : [ "timestream:ListScheduledQueries", "timestream:DescribeEndpoints" ]
    }
  }
}