awswrangler.cloudwatch.run_query

awswrangler.cloudwatch.run_query(query: str, log_group_names: List[str], start_time: datetime.datetime = datetime.datetime(1970, 1, 1, 0, 0), end_time: datetime.datetime = datetime.datetime(2020, 5, 20, 14, 9, 32, 117078), limit: Optional[int] = None, boto3_session: Optional[boto3.session.Session] = None) → List[List[Dict[str, str]]]

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

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

Parameters
  • query (str) – The query string.

  • log_group_names (str) – The list of log groups to be queried. You can include up to 20 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 (Optional[int]) – 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.

Returns

Result.

Return type

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

Examples

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