Skip to content

create_scheduled_query

create_scheduled_query(
    name: ScheduledQueryName,
    query_language: QueryLanguage,
    query_string: QueryString,
    schedule_expression: ScheduleExpression,
    execution_role_arn: RoleArn,
    *,
    config_overrides: Optional[CloudWatchLogsClientConfig] = None,
    description: Optional[ScheduledQueryDescription] = None,
    log_group_identifiers: Optional[ScheduledQueryLogGroupIdentifiers] = None,
    timezone: Optional[ScheduleTimezone] = None,
    start_time_offset: Optional[StartTimeOffset] = None,
    end_time_offset: Optional[EndTimeOffset] = None,
    destination_configuration: Optional[DestinationConfiguration] = None,
    schedule_start_time: Optional[Timestamp] = None,
    schedule_end_time: Optional[Timestamp] = None,
    state: Optional[ScheduledQueryState] = None,
    tags: Optional[Tags] = None,
) -> CreateScheduledQueryResponse

Creates a scheduled query that runs CloudWatch Logs Insights queries at regular intervals. Scheduled queries enable proactive monitoring by automatically executing queries to detect patterns and anomalies in your log data. Query results can be delivered to Amazon S3 for analysis or further processing.

Parameters:

  • name (ScheduledQueryName) –

    The name of the scheduled query. The name must be unique within your account and region. Length must be between 1 and 300 characters.

  • description (Optional[ScheduledQueryDescription], default: None ) –

    An optional description for the scheduled query to help identify its purpose and functionality.

  • query_language (QueryLanguage) –

    The query language to use for the scheduled query. Valid values are CWLI, PPL, and SQL.

  • query_string (QueryString) –

    The query string to execute. This is the same query syntax used in CloudWatch Logs Insights. Maximum length is 10,000 characters.

  • log_group_identifiers (Optional[ScheduledQueryLogGroupIdentifiers], default: None ) –

    An array of log group names or ARNs to query. You can specify between 1 and 50 log groups. Log groups can be identified by name or full ARN.

  • schedule_expression (ScheduleExpression) –

    A cron expression that defines when the scheduled query runs. The expression uses standard cron syntax and supports minute-level precision. Maximum length is 256 characters.

  • timezone (Optional[ScheduleTimezone], default: None ) –

    The timezone for evaluating the schedule expression. This determines when the scheduled query executes relative to the specified timezone.

  • start_time_offset (Optional[StartTimeOffset], default: None ) –

    The time offset in seconds that defines the lookback period for the query. This determines how far back in time the query searches from the execution time.

  • end_time_offset (Optional[EndTimeOffset], default: None ) –

    The time offset in seconds that defines the end of the lookback period for the query. Together with startTimeOffset, this determines the time window relative to the execution time over which the query runs.

  • destination_configuration (Optional[DestinationConfiguration], default: None ) –

    Configuration for where to deliver query results. Supports Amazon S3 destinations for storing query output and lookup table destinations for automatically refreshing lookup tables with query results. You can configure one or both destination types.

  • schedule_start_time (Optional[Timestamp], default: None ) –

    The start time for the scheduled query in Unix epoch format. The query will not execute before this time.

  • schedule_end_time (Optional[Timestamp], default: None ) –

    The end time for the scheduled query in Unix epoch format. The query will stop executing after this time.

  • execution_role_arn (RoleArn) –

    The ARN of the IAM role that grants permissions to execute the query and deliver results to the specified destination. The role must have permissions to read from the specified log groups and write to the destination.

  • state (Optional[ScheduledQueryState], default: None ) –

    The initial state of the scheduled query. Valid values are ENABLED and DISABLED. Default is ENABLED.

  • tags (Optional[Tags], default: None ) –

    Key-value pairs to associate with the scheduled query for resource management and cost allocation.

Raises:

Source code in docs_src/capo_cloudwatch_logs/_services/cloud_watch_logs.py
def create_scheduled_query(
    self,
    name: "capo_cloudwatch_logs.types.scheduled_query_name.ScheduledQueryName",
    query_language: "capo_cloudwatch_logs.types.query_language.QueryLanguage",
    query_string: "capo_cloudwatch_logs.types.query_string.QueryString",
    schedule_expression: "capo_cloudwatch_logs.types.schedule_expression.ScheduleExpression",
    execution_role_arn: "capo_cloudwatch_logs.types.role_arn.RoleArn",
    *,
    config_overrides: Optional[CloudWatchLogsClientConfig] = None,
    description: Optional[
        "capo_cloudwatch_logs.types.scheduled_query_description.ScheduledQueryDescription"
    ] = None,
    log_group_identifiers: Optional[
        "capo_cloudwatch_logs.types.scheduled_query_log_group_identifiers.ScheduledQueryLogGroupIdentifiers"
    ] = None,
    timezone: Optional[
        "capo_cloudwatch_logs.types.schedule_timezone.ScheduleTimezone"
    ] = None,
    start_time_offset: Optional[
        "capo_cloudwatch_logs.types.start_time_offset.StartTimeOffset"
    ] = None,
    end_time_offset: Optional[
        "capo_cloudwatch_logs.types.end_time_offset.EndTimeOffset"
    ] = None,
    destination_configuration: Optional[
        "capo_cloudwatch_logs.types.destination_configuration.DestinationConfiguration"
    ] = None,
    schedule_start_time: Optional[
        "capo_cloudwatch_logs.types.timestamp.Timestamp"
    ] = None,
    schedule_end_time: Optional[
        "capo_cloudwatch_logs.types.timestamp.Timestamp"
    ] = None,
    state: Optional[
        "capo_cloudwatch_logs.types.scheduled_query_state.ScheduledQueryState"
    ] = None,
    tags: Optional["capo_cloudwatch_logs.types.tags.Tags"] = None,
) -> "capo_cloudwatch_logs.types.create_scheduled_query_response.CreateScheduledQueryResponse":
    """<p>Creates a scheduled query that runs CloudWatch Logs Insights queries at regular intervals. Scheduled queries enable proactive monitoring by automatically executing queries to detect patterns and anomalies in your log data. Query results can be delivered to Amazon S3 for analysis or further processing.</p>

    Args:
        name: <p>The name of the scheduled query. The name must be unique within your account and region. Length must be between 1 and 300 characters.</p>
        description: <p>An optional description for the scheduled query to help identify its purpose and functionality.</p>
        query_language: <p>The query language to use for the scheduled query. Valid values are <code>CWLI</code>, <code>PPL</code>, and <code>SQL</code>.</p>
        query_string: <p>The query string to execute. This is the same query syntax used in CloudWatch Logs Insights. Maximum length is 10,000 characters.</p>
        log_group_identifiers: <p>An array of log group names or ARNs to query. You can specify between 1 and 50 log groups. Log groups can be identified by name or full ARN.</p>
        schedule_expression: <p>A cron expression that defines when the scheduled query runs. The expression uses standard cron syntax and supports minute-level precision. Maximum length is 256 characters.</p>
        timezone: <p>The timezone for evaluating the schedule expression. This determines when the scheduled query executes relative to the specified timezone.</p>
        start_time_offset: <p>The time offset in seconds that defines the lookback period for the query. This determines how far back in time the query searches from the execution time.</p>
        end_time_offset: <p>The time offset in seconds that defines the end of the lookback period for the query. Together with <code>startTimeOffset</code>, this determines the time window relative to the execution time over which the query runs.</p>
        destination_configuration: <p>Configuration for where to deliver query results. Supports Amazon S3 destinations for storing query output and lookup table destinations for automatically refreshing lookup tables with query results. You can configure one or both destination types.</p>
        schedule_start_time: <p>The start time for the scheduled query in Unix epoch format. The query will not execute before this time.</p>
        schedule_end_time: <p>The end time for the scheduled query in Unix epoch format. The query will stop executing after this time.</p>
        execution_role_arn: <p>The ARN of the IAM role that grants permissions to execute the query and deliver results to the specified destination. The role must have permissions to read from the specified log groups and write to the destination.</p>
        state: <p>The initial state of the scheduled query. Valid values are <code>ENABLED</code> and <code>DISABLED</code>. Default is <code>ENABLED</code>.</p>
        tags: <p>Key-value pairs to associate with the scheduled query for resource management and cost allocation.</p>

    Raises:
        capo_cloudwatch_logs.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient permissions to perform this action.</p>
        capo_cloudwatch_logs.errors.conflict_exception.ConflictException: <p>This operation attempted to create a resource that already exists.</p>
        capo_cloudwatch_logs.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred while processing the request. This exception is returned when the service encounters an unexpected condition that prevents it from fulfilling the request.</p>
        capo_cloudwatch_logs.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
        capo_cloudwatch_logs.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>This request exceeds a service quota.</p>
        capo_cloudwatch_logs.errors.throttling_exception.ThrottlingException: <p>The request was throttled because of quota limits.</p>
        capo_cloudwatch_logs.errors.validation_exception.ValidationException: <p>One of the parameters for the request is not valid.</p>
        capo_cloudwatch_logs.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatch_logs.types.create_scheduled_query_request.CreateScheduledQueryRequest]",
    ) -> OperationResponse[
        "capo_cloudwatch_logs.types.create_scheduled_query_response.CreateScheduledQueryResponse"
    ]:
        import capo_cloudwatch_logs._operations.logs_20140328.create_scheduled_query

        output, http_response = (
            capo_cloudwatch_logs._operations.logs_20140328.create_scheduled_query.create_scheduled_query(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateScheduledQuery")
    )
    input_: capo_cloudwatch_logs.types.create_scheduled_query_request.CreateScheduledQueryRequest = {
        "name": name,
        "query_language": query_language,
        "query_string": query_string,
        "schedule_expression": schedule_expression,
        "execution_role_arn": execution_role_arn,
    }
    if description is not None:
        input_["description"] = description
    if log_group_identifiers is not None:
        input_["log_group_identifiers"] = log_group_identifiers
    if timezone is not None:
        input_["timezone"] = timezone
    if start_time_offset is not None:
        input_["start_time_offset"] = start_time_offset
    if end_time_offset is not None:
        input_["end_time_offset"] = end_time_offset
    if destination_configuration is not None:
        input_["destination_configuration"] = destination_configuration
    if schedule_start_time is not None:
        input_["schedule_start_time"] = schedule_start_time
    if schedule_end_time is not None:
        input_["schedule_end_time"] = schedule_end_time
    if state is not None:
        input_["state"] = state
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output