start_query
async
¶
start_query(
start_time: Timestamp,
end_time: Timestamp,
query_string: QueryString,
*,
config_overrides: Optional[AsyncCloudWatchLogsClientConfig] = None,
query_language: Optional[QueryLanguage] = None,
log_group_name: Optional[LogGroupName] = None,
log_group_names: Optional[LogGroupNames] = None,
log_group_identifiers: Optional[LogGroupIdentifiers] = None,
limit: Optional[EventsLimitStartQuery] = None,
) -> StartQueryResponse
Starts a query of one or more log groups or data sources using CloudWatch Logs Insights. You specify the log groups or data sources and time range to query and the query string to use. You can query up to 10 data sources in a single query.
For more information, see CloudWatch Logs Insights Query Syntax.
After you run a query using StartQuery, the query results are stored by CloudWatch Logs. You can use GetQueryResults to retrieve the results of a query, using the queryId that StartQuery returns.
Interactive queries started with StartQuery share concurrency limits with automated scheduled query executions. Both types of queries count toward the same regional concurrent query quota, so high scheduled query activity may affect the availability of concurrent slots for interactive queries.
To specify the log groups to query, a StartQuery operation must include one of the following:
-
Either exactly one of the following parameters:
logGroupName,logGroupNames, orlogGroupIdentifiers -
Or the
queryStringmust include aSOURCEcommand to select log groups for the query. TheSOURCEcommand can select log groups based on log group name prefix, account ID, and log class, or select data sources using dataSource syntax in LogsQL, PPL, and SQL. In LogsQL, theSOURCEcommand also supports filtering by log group tags.For more information about the
SOURCEcommand, see SOURCE.
If you have associated a KMS key with the query results in this account, then StartQuery uses that key to encrypt the results when it stores them. If no key is associated with query results, the query results are encrypted with the default CloudWatch Logs encryption method.
Queries time out after 60 minutes of runtime. If your queries are timing out, reduce the time range being searched or partition your query into a number of queries.
If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account to start a query in a linked source account. For more information, see CloudWatch cross-account observability. For a cross-account StartQuery operation, the query definition must be defined in the monitoring account.
You can have up to 100 concurrent CloudWatch Logs insights queries, including queries that have been added to dashboards.
Parameters:
-
query_language(Optional[QueryLanguage], default:None) –Specify the query language to use for this query. The options are Logs Insights QL, OpenSearch PPL, and OpenSearch SQL. For more information about the query languages that CloudWatch Logs supports, see Supported query languages.
-
log_group_name(Optional[LogGroupName], default:None) –The log group on which to perform the query.
A
StartQueryoperation must include exactly one of the following parameters:logGroupName,logGroupNames, orlogGroupIdentifiers. The exception is queries using the OpenSearch Service SQL query language, where you specify the log group names inside thequerystringinstead of here. -
log_group_names(Optional[LogGroupNames], default:None) –The list of log groups to be queried. You can include up to 50 log groups.
A
StartQueryoperation must include exactly one of the following parameters:logGroupName,logGroupNames, orlogGroupIdentifiers. The exception is queries using the OpenSearch Service SQL query language, where you specify the log group names inside thequerystringinstead of here. -
log_group_identifiers(Optional[LogGroupIdentifiers], default:None) –The list of log groups to query. You can include up to 50 log groups.
You can specify them by the log group name or ARN. If a log group that you're querying is in a source account and you're using a monitoring account, you must specify the ARN of the log group here. The query definition must also be defined in the monitoring account.
If you specify an ARN, use the format arn:aws:logs:region:account-id:log-group:log_group_name Don't include an * at the end.
A
StartQueryoperation must include exactly one of the following parameters:logGroupName,logGroupNames, orlogGroupIdentifiers. The exception is queries using the OpenSearch Service SQL query language, where you specify the log group names inside thequerystringinstead of here. -
start_time(Timestamp) –The beginning of the time range to query. The range is inclusive, so the specified start time is included in the query. Specified as epoch time, the number of seconds since
January 1, 1970, 00:00:00 UTC. -
end_time(Timestamp) –The end of the time range to query. The range is inclusive, so the specified end time is included in the query. Specified as epoch time, the number of seconds since
January 1, 1970, 00:00:00 UTC. -
query_string(QueryString) –The query string to use. For more information, see CloudWatch Logs Insights Query Syntax.
-
limit(Optional[EventsLimitStartQuery], default:None) –The maximum number of log events to return from the query. The maximum limit is 100,000. The maximum events returned in a single GetQueryResults API call is 10,000 log events per request. You can retrieve up to 100,000 log event results from a query by paginating with the
nextToken. 100,000 limit is only supported for Logs Insights QL and is currently not supported for PPL and SQL query languages.
Raises:
-
InvalidParameterException–A parameter is specified incorrectly.
-
LimitExceededException–You have reached the maximum number of resources that can be created.
-
MalformedQueryException–The query string is not valid. Details about this error are displayed in a
QueryCompileErrorobject. For more information, see QueryCompileError.For more information about valid query syntax, see CloudWatch Logs Insights Query Syntax.
-
ResourceNotFoundException–The specified resource does not exist.
-
ServiceUnavailableException–The service cannot complete the request.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_cloudwatch_logs/_services/async_cloud_watch_logs.py
7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 | |