awswrangler.cloudwatch.run_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) list[list[dict[str, str]]]

Run a query against AWS CloudWatchLogs Insights and wait the results.

  • 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.datetime) – The beginning of the time range to query.

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

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

  • boto3_session (boto3.Session(), optional) – Boto3 Session. The default boto3 session will be used if boto3_session receive None.



Return type:

List[List[Dict[str, str]]]


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