getQueryResults method
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.
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.
May throw InvalidParameterException.
May throw ResourceNotFoundException.
May throw ServiceUnavailableException.
Parameter queryId :
The ID number of the query.
Parameter maxItems :
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.
Parameter nextToken :
The token for the next set of items to return. The token expires after 1
hour.
Implementation
Future<GetQueryResultsResponse> getQueryResults({
required String queryId,
int? maxItems,
String? nextToken,
}) async {
_s.validateNumRange(
'maxItems',
maxItems,
0,
10000,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'Logs_20140328.GetQueryResults'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'queryId': queryId,
if (maxItems != null) 'maxItems': maxItems,
if (nextToken != null) 'nextToken': nextToken,
},
);
return GetQueryResultsResponse.fromJson(jsonResponse.body);
}