awswrangler.cloudwatch.start_query

awswrangler.cloudwatch.start_query(query: str, log_group_names: list[str], start_time: datetime | None = None, end_time: datetime | None = None, limit: int | None = None, boto3_session: Session | None = None) str

Run a query against AWS CloudWatchLogs Insights.

https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html

Parameters:
  • query (str) – The query string.

  • log_group_names (list[str]) – The list of log group names or ARNs to be queried. You can include up to 50 log groups.

  • start_time (datetime | None) – The beginning of the time range to query.

  • end_time (datetime | None) – The end of the time range to query.

  • limit (int | None) – The maximum number of log events to return in the query.

  • boto3_session (Session | None) – The default boto3 session will be used if boto3_session is None.

Return type:

str

Returns:

Query ID.

Examples

>>> import awswrangler as wr
>>> query_id = wr.cloudwatch.start_query(
...     log_group_names=["loggroup"],
...     query="fields @timestamp, @message | sort @timestamp desc | limit 5",
... )