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
I seguenti esempi di codice mostrano come usareGetQueryResults.
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)
-
/// <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;
}
}
- JavaScript
-
- SDK per JavaScript (v3)
-
/**
* Simple wrapper for the GetQueryResultsCommand.
* @param {string} queryId
*/
_getQueryResults(queryId) {
return this.client.send(new GetQueryResultsCommand({ queryId }));
}
- Python
-
- SDK per Python (Boto3)
-
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", [])
- SAP ABAP
-
- SDK per SAP ABAP
-
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 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.