Amazon CloudWatch Logs
API Reference (API Version 2014-03-28)

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

GetQueryResults

Returns the results from the specified query.

Only the fields requested in the query are returned, along with a @ptr field which is the identifier for the log record. You can use the value of @ptr in a GetLogRecord operation to get the full log record.

GetQueryResults does not start a query execution. To run a query, use StartQuery.

If the value of the Status field in the output is Running, this operation returns only partial results. If you see a value of Scheduled or Running for the status, you can retry the operation later to see the final results.

Request Syntax

{ "queryId": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

queryId

The ID number of the query.

Type: String

Length Constraints: Minimum length of 0. Maximum length of 256.

Required: Yes

Response Syntax

{ "results": [ [ { "field": "string", "value": "string" } ] ], "statistics": { "bytesScanned": number, "recordsMatched": number, "recordsScanned": number }, "status": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

results

The log events that matched the query criteria during the most recent time it ran.

The results value is an array of arrays. Each log event is one object in the top-level array. Each of these log event objects is an array of field/value pairs.

Type: Array of arrays of ResultField objects

statistics

Includes the number of log events scanned by the query, the number of log events that matched the query criteria, and the total number of bytes in the log events that were scanned.

Type: QueryStatistics object

status

The status of the most recent running of the query. Possible values are Cancelled, Complete, Failed, Running, Scheduled, Timeout, and Unknown.

Queries time out after 15 minutes of execution. To avoid having your queries time out, reduce the time range being searched, or partition your query into a number of queries.

Type: String

Valid Values: Scheduled | Running | Complete | Failed | Cancelled

Errors

For information about the errors that are common to all actions, see Common Errors.

InvalidParameterException

A parameter is specified incorrectly.

HTTP Status Code: 400

ResourceNotFoundException

The specified resource does not exist.

HTTP Status Code: 400

ServiceUnavailableException

The service cannot complete the request.

HTTP Status Code: 500

Example

Get results from a recent query

The following returns the results from a specified query.

Sample Request

POST / HTTP/1.1 Host: logs.<region>.<domain> X-Amz-Date: <DATE> Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=content-type;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid, Signature=<Signature> User-Agent: <UserAgentString> Accept: application/json Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Connection: Keep-Alive X-Amz-Target: Logs_20140328.GetQueryResults { "queryId": "12ab3456-12ab-123a-789e-1234567890ab" }

Sample Response

HTTP/1.1 200 OK x-amzn-RequestId: <RequestId> Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Date: <Date> { "results": [ [ { "field": "LogEvent1-field1-name", "value": "LogEvent1-field1-value" }, { "field": "LogEvent1-field2-name", "value": "LogEvent1-field2-value" }, ... { "field": "LogEvent1-fieldX-name", "value": "LogEvent1-fieldX-value" } ], [ { "field": "LogEvent2-field1-name", "value": "LogEvent2-field1-value" }, { "field": "LogEvent2-field2-name", "value": "LogEvent2-field2-value" }, ... { "field": "LogEvent2-fieldX-name", "value": "LogEvent2-fieldX-value" } ], [ { "field": "LogEventZ-field1-name", "value": "LogEventZ-field1-value" }, { "field": "LogEventZ-field2-name", "value": "LogEventZ-field2-value" }, ... { "field": "LogEventZ-fieldX-name", "value": "LogEventZ-fieldX-value" } ] ], "statistics": { "bytesScanned": 81349723, "recordsMatched": 360851, "recordsScanned": 610956 }, "status": "Completed" }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: