startQuery method

Future<StartQueryResponse> startQuery({
  1. required int endTime,
  2. required String queryString,
  3. required int startTime,
  4. int? limit,
  5. String? logGroupName,
  6. List<String>? logGroupNames,
})

Schedules a query of a log group using CloudWatch Logs Insights. You specify the log group and time range to query and the query string to use.

For more information, see CloudWatch Logs Insights Query Syntax.

Queries time out after 15 minutes of execution. If your queries are timing out, reduce the time range being searched or partition your query into a number of queries.

May throw MalformedQueryException. May throw InvalidParameterException. May throw LimitExceededException. May throw ResourceNotFoundException. May throw ServiceUnavailableException.

Parameter endTime : The end of the time range to query. The range is inclusive, so the specified end time is included in the query. Specified as epoch time, the number of seconds since January 1, 1970, 00:00:00 UTC.

Parameter queryString : The query string to use. For more information, see CloudWatch Logs Insights Query Syntax.

Parameter startTime : The beginning of the time range to query. The range is inclusive, so the specified start time is included in the query. Specified as epoch time, the number of seconds since January 1, 1970, 00:00:00 UTC.

Parameter limit : The maximum number of log events to return in the query. If the query string uses the fields command, only the specified fields and their values are returned. The default is 1000.

Parameter logGroupName : The log group on which to perform the query.

A StartQuery operation must include a logGroupNames or a logGroupName parameter, but not both.

Parameter logGroupNames : The list of log groups to be queried. You can include up to 20 log groups.

A StartQuery operation must include a logGroupNames or a logGroupName parameter, but not both.

Implementation

Future<StartQueryResponse> startQuery({
  required int endTime,
  required String queryString,
  required int startTime,
  int? limit,
  String? logGroupName,
  List<String>? logGroupNames,
}) async {
  ArgumentError.checkNotNull(endTime, 'endTime');
  _s.validateNumRange(
    'endTime',
    endTime,
    0,
    1152921504606846976,
    isRequired: true,
  );
  ArgumentError.checkNotNull(queryString, 'queryString');
  _s.validateStringLength(
    'queryString',
    queryString,
    0,
    10000,
    isRequired: true,
  );
  ArgumentError.checkNotNull(startTime, 'startTime');
  _s.validateNumRange(
    'startTime',
    startTime,
    0,
    1152921504606846976,
    isRequired: true,
  );
  _s.validateNumRange(
    'limit',
    limit,
    1,
    10000,
  );
  _s.validateStringLength(
    'logGroupName',
    logGroupName,
    1,
    512,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Logs_20140328.StartQuery'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'endTime': endTime,
      'queryString': queryString,
      'startTime': startTime,
      if (limit != null) 'limit': limit,
      if (logGroupName != null) 'logGroupName': logGroupName,
      if (logGroupNames != null) 'logGroupNames': logGroupNames,
    },
  );

  return StartQueryResponse.fromJson(jsonResponse.body);
}