View a markdown version of this page

Da usare GetQueryResults con un AWS SDK - CloudWatch Registri Amazon

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Da usare GetQueryResults con un AWS SDK

Gli esempi di codice seguenti mostrano come utilizzare GetQueryResults.

Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:

.NET
SDK per .NET (v4)
Nota

C'è altro su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/// <summary> /// Gets the results of a CloudWatch Logs Insights query. /// </summary> /// <param name="queryId">The ID of the query.</param> /// <returns>The query results response.</returns> public async Task<GetQueryResultsResponse?> GetQueryResultsAsync(string queryId) { try { var request = new GetQueryResultsRequest { QueryId = queryId }; var response = await _amazonCloudWatchLogs.GetQueryResultsAsync(request); return response; } catch (ResourceNotFoundException ex) { _logger.LogError($"Query not found: {ex.Message}"); return null; } catch (Exception ex) { _logger.LogError($"An error occurred while getting query results: {ex.Message}"); return null; } }
  • Per i dettagli sulle API, consulta la GetQueryResults sezione AWS SDK per .NET API Reference.

JavaScript
SDK per JavaScript (v3)
Nota

C'è altro su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/** * Simple wrapper for the GetQueryResultsCommand. * @param {string} queryId */ _getQueryResults(queryId) { return this.client.send(new GetQueryResultsCommand({ queryId })); }
  • Per i dettagli sulle API, consulta la GetQueryResults sezione AWS SDK per JavaScript API Reference.

Python
SDK per Python (Boto3)
Nota

C'è altro su GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

def _wait_for_query_results(self, client, query_id): """ Waits for the query to complete and retrieves the results. :param query_id: The ID of the initiated query. :type query_id: str :return: A list containing the results of the query. :rtype: list """ while True: time.sleep(1) results = client.get_query_results(queryId=query_id) if results["status"] in [ "Complete", "Failed", "Cancelled", "Timeout", "Unknown", ]: return results.get("results", [])
  • Per i dettagli sulle API, vedi GetQueryResults in AWS SDK for Python (Boto3) API Reference.

SAP ABAP
SDK per SAP ABAP
Nota

C'è altro su. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

TRY. oo_result = lo_cwl->getqueryresults( iv_queryid = iv_query_id ). " Display query status and result count DATA(lv_status) = oo_result->get_status( ). DATA(lt_results) = oo_result->get_results( ). DATA(lv_result_count) = lines( lt_results ). MESSAGE |Query status: { lv_status }. Retrieved { lv_result_count } log event(s).| TYPE 'I'. CATCH /aws1/cx_cwlinvalidparameterex. MESSAGE 'Invalid parameter.' TYPE 'E'. CATCH /aws1/cx_cwlresourcenotfoundex. MESSAGE 'Resource not found.' TYPE 'E'. CATCH /aws1/cx_cwlserviceunavailex. MESSAGE 'Service unavailable.' TYPE 'E'. ENDTRY.
  • Per i dettagli sulle API, consulta GetQueryResults la sezione AWS SDK for SAP ABAP API Reference.

Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. Usare i CloudWatch log con un AWS SDK Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.