generateQuery method

Future<GenerateQueryResponse> generateQuery({
  1. required List<String> eventDataStores,
  2. required String prompt,
})

Generates a query from a natural language prompt. This operation uses generative artificial intelligence (generative AI) to produce a ready-to-use SQL query from the prompt.

The prompt can be a question or a statement about the event data in your event data store. For example, you can enter prompts like "What are my top errors in the past month?" and “Give me a list of users that used SNS.”

The prompt must be in English. For information about limitations, permissions, and supported Regions, see Create CloudTrail Lake queries from natural language prompts in the CloudTrail user guide.

This feature uses generative AI large language models (LLMs); we recommend double-checking the LLM response.

May throw EventDataStoreARNInvalidException. May throw EventDataStoreNotFoundException. May throw GenerateResponseException. May throw InactiveEventDataStoreException. May throw InvalidParameterException. May throw NoManagementAccountSLRExistsException. May throw OperationNotPermittedException. May throw UnsupportedOperationException.

Parameter eventDataStores : The ARN (or ID suffix of the ARN) of the event data store that you want to query. You can only specify one event data store.

Parameter prompt : The prompt that you want to use to generate the query. The prompt must be in English. For example prompts, see Example prompts in the CloudTrail user guide.

Implementation

Future<GenerateQueryResponse> generateQuery({
  required List<String> eventDataStores,
  required String prompt,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'CloudTrail_20131101.GenerateQuery'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'EventDataStores': eventDataStores,
      'Prompt': prompt,
    },
  );

  return GenerateQueryResponse.fromJson(jsonResponse.body);
}