There are more AWS SDK examples available in the AWS Doc SDK Examples
Use GetQueryResults with an AWS SDK
The following code examples show how to use GetQueryResults.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- .NET
-
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. /// <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; } }-
For API details, see GetQueryResults in AWS SDK for .NET API Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. /** * Simple wrapper for the GetQueryResultsCommand. * @param {string} queryId */ _getQueryResults(queryId) { return this.client.send(new GetQueryResultsCommand({ queryId })); }-
For API details, see GetQueryResults in AWS SDK for JavaScript API Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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", [])-
For API details, see GetQueryResults in AWS SDK for Python (Boto3) API Reference.
-