Skip to content

get_query_results async

get_query_results(
    query_id: QueryId,
    *,
    config_overrides: Optional[AsyncCloudWatchLogsClientConfig] = None,
    next_token: Optional[GetQueryResultsNextToken] = None,
    max_items: Optional[GetQueryResultsMaxItems] = None,
) -> GetQueryResultsResponse

Returns the results from the specified query.

Only the fields requested in the query are returned, along with a @ptr field, which is the identifier for the log record. You can use the value of @ptr in a GetLogRecord operation to get the full log record.

GetQueryResults does not start running a query. To run a query, use StartQuery. For more information about how long results of previous queries are available, see CloudWatch Logs quotas.

If the value of the Status field in the output is Running, this operation returns only partial results. If you see a value of Scheduled or Running for the status, you can retry the operation later to see the final results.

This operation is used both for retrieving results from interactive queries and from automated scheduled query executions. Scheduled queries use GetQueryResults internally to retrieve query results for processing and delivery to configured destinations.

You can retrieve up to 100,000 log event results from a query, if available, by using pagination. Use the nextToken returned in the response to request additional pages of results, with each page returning up to 10,000 log events. This is only supported for Logs Insights QL and is currently not supported for PPL and SQL query languages.

If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account to start queries in linked source accounts. For more information, see CloudWatch cross-account observability.

Parameters:

  • query_id (QueryId) –

    The ID number of the query.

  • next_token (Optional[GetQueryResultsNextToken], default: None ) –

    The token for the next set of items to return. The token expires after 1 hour.

  • max_items (Optional[GetQueryResultsMaxItems], default: None ) –

    The maximum number of log events to return in the response. The maximum 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.

Raises:

Source code in docs_src/capo_cloudwatch_logs/_services/async_cloud_watch_logs.py
async def get_query_results(
    self,
    query_id: "capo_cloudwatch_logs.types.query_id.QueryId",
    *,
    config_overrides: Optional[AsyncCloudWatchLogsClientConfig] = None,
    next_token: Optional[
        "capo_cloudwatch_logs.types.get_query_results_next_token.GetQueryResultsNextToken"
    ] = None,
    max_items: Optional[
        "capo_cloudwatch_logs.types.get_query_results_max_items.GetQueryResultsMaxItems"
    ] = None,
) -> (
    "capo_cloudwatch_logs.types.get_query_results_response.GetQueryResultsResponse"
):
    """<p>Returns the results from the specified query.</p> <p>Only the fields requested in the query are returned, along with a <code>@ptr</code> field, which is the identifier for the log record. You can use the value of <code>@ptr</code> in a <a href="https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_GetLogRecord.html">GetLogRecord</a> operation to get the full log record.</p> <p> <code>GetQueryResults</code> does not start running a query. To run a query, use <a href="https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_StartQuery.html">StartQuery</a>. For more information about how long results of previous queries are available, see <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html">CloudWatch Logs quotas</a>.</p> <p>If the value of the <code>Status</code> field in the output is <code>Running</code>, this operation returns only partial results. If you see a value of <code>Scheduled</code> or <code>Running</code> for the status, you can retry the operation later to see the final results. </p> <p>This operation is used both for retrieving results from interactive queries and from automated scheduled query executions. Scheduled queries use <code>GetQueryResults</code> internally to retrieve query results for processing and delivery to configured destinations.</p> <p>You can retrieve up to 100,000 log event results from a query, if available, by using pagination. Use the <code>nextToken</code> returned in the response to request additional pages of results, with each page returning up to 10,000 log events. This is only supported for Logs Insights QL and is currently not supported for PPL and SQL query languages.</p> <p>If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account to start queries in linked source accounts. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account.html">CloudWatch cross-account observability</a>.</p>

    Args:
        query_id: <p>The ID number of the query.</p>
        next_token: <p>The token for the next set of items to return. The token expires after 1 hour.</p>
        max_items: <p>The maximum number of log events to return in the response. The maximum is 10,000 log events per request. You can retrieve up to 100,000 log event results from a query by paginating with the <code>nextToken</code>.</p>

    Raises:
        capo_cloudwatch_logs.errors.invalid_parameter_exception.InvalidParameterException: <p>A parameter is specified incorrectly.</p>
        capo_cloudwatch_logs.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
        capo_cloudwatch_logs.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service cannot complete the request.</p>
        capo_cloudwatch_logs.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_cloudwatch_logs.types.get_query_results_request.GetQueryResultsRequest]",
    ) -> AsyncOperationResponse[
        "capo_cloudwatch_logs.types.get_query_results_response.GetQueryResultsResponse"
    ]:
        import capo_cloudwatch_logs._operations.logs_20140328.get_query_results

        (
            output,
            http_response,
        ) = await capo_cloudwatch_logs._operations.logs_20140328.get_query_results.async_get_query_results(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetQueryResults")
    )
    input_: capo_cloudwatch_logs.types.get_query_results_request.GetQueryResultsRequest = {
        "query_id": query_id
    }
    if next_token is not None:
        input_["next_token"] = next_token
    if max_items is not None:
        input_["max_items"] = max_items

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output