CloudWatchLogs / Client / create_scheduled_query

create_scheduled_query

CloudWatchLogs.Client.create_scheduled_query(**kwargs)

Creates a new Scheduled Query that runs CloudWatch Logs Insights queries on a schedule and delivers results to specified destinations.

See also: AWS API Documentation

Request Syntax

response = client.create_scheduled_query(
    name='string',
    description='string',
    queryLanguage='CWLI'|'SQL'|'PPL',
    queryString='string',
    logGroupIdentifiers=[
        'string',
    ],
    scheduleExpression='string',
    timezone='string',
    startTimeOffset=123,
    destinationConfiguration={
        's3Configuration': {
            'destinationIdentifier': 'string',
            'roleArn': 'string'
        }
    },
    scheduleStartTime=123,
    scheduleEndTime=123,
    executionRoleArn='string',
    state='ENABLED'|'DISABLED',
    tags={
        'string': 'string'
    }
)
Parameters:
  • name (string) –

    [REQUIRED]

    A unique name for the scheduled query within the region for an AWS account. The name can contain letters, numbers, underscores, hyphens, forward slashes, periods, and hash symbols.

  • description (string) – An optional description for the scheduled query to help identify its purpose.

  • queryLanguage (string) –

    [REQUIRED]

    The query language to use for the scheduled query. Valid values are LogsQL (CloudWatch Logs Insights query language), PPL (OpenSearch Service Piped Processing Language), and SQL (OpenSearch Service Structured Query Language).

  • queryString (string) –

    [REQUIRED]

    The CloudWatch Logs Insights query string to execute. This is the actual query that will be run against your log data on the specified schedule.

  • logGroupIdentifiers (list) –

    The log group identifiers to query. You can specify log group names or log group ARNs. If querying log groups in a source account from a monitoring account, you must specify the ARN of the log group.

    • (string) –

  • scheduleExpression (string) –

    [REQUIRED]

    A cron expression that defines when the scheduled query runs. The format is cron(fields) where fields consist of six space-separated values: minutes, hours, day_of_month, month, day_of_week, year.

  • timezone (string) – The timezone in which the schedule expression is evaluated. If not provided, defaults to UTC.

  • startTimeOffset (integer) – Time offset in seconds from the execution time for the start of the query time range. This defines the lookback period for the query (for example, 3600 for the last hour).

  • destinationConfiguration (dict) –

    Configuration for destinations where the query results will be delivered after successful execution. You can configure delivery to S3 buckets or EventBridge event buses.

    • s3Configuration (dict) – [REQUIRED]

      Configuration for delivering query results to an Amazon S3 bucket.

      • destinationIdentifier (string) – [REQUIRED]

        The S3 URI where query results will be stored (e.g., s3://bucket-name/prefix/).

      • roleArn (string) – [REQUIRED]

        The ARN of the IAM role that CloudWatch Logs will assume to write results to the S3 bucket.

  • scheduleStartTime (integer) – The start time for the query schedule in Unix epoch time (seconds since January 1, 1970, 00:00:00 UTC). If not specified, the schedule starts immediately.

  • scheduleEndTime (integer) – The end time for the query schedule in Unix epoch time (seconds since January 1, 1970, 00:00:00 UTC). If not specified, the schedule runs indefinitely.

  • executionRoleArn (string) –

    [REQUIRED]

    The Amazon Resource Name (ARN) of the IAM role that CloudWatch Logs will assume to execute the scheduled query and deliver results to the specified destinations.

  • state (string) – The initial state of the scheduled query. Valid values are ENABLED (the query will run according to its schedule) and DISABLED (the query is paused and will not run). If not provided, defaults to ENABLED.

  • tags (dict) –

    An optional list of key-value pairs to associate with the resource.

    For more information about tagging, see Tagging Amazon Web Services resources

    • (string) –

      • (string) –

Return type:

dict

Returns:

Response Syntax

{
    'scheduledQueryArn': 'string',
    'state': 'ENABLED'|'DISABLED'
}

Response Structure

  • (dict) –

    • scheduledQueryArn (string) –

      The Amazon Resource Name (ARN) of the created scheduled query.

    • state (string) –

      The current state of the scheduled query (ENABLED or DISABLED).

Exceptions