GetLogEvents - Amazon CloudWatch Logs

GetLogEvents

Lists log events from the specified log stream. You can list all of the log events or filter using a time range.

By default, this operation returns as many log events as can fit in a response size of 1MB (up to 10,000 log events). You can get additional log events by specifying one of the tokens in a subsequent call. This operation can return empty results while there are more log events available through the token.

If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account and view data from the linked source accounts. For more information, see CloudWatch cross-account observability.

You can specify the log group to search by using either logGroupIdentifier or logGroupName. You must include one of these two parameters, but you can't include both.

Request Syntax

{ "endTime": number, "limit": number, "logGroupIdentifier": "string", "logGroupName": "string", "logStreamName": "string", "nextToken": "string", "startFromHead": boolean, "startTime": number, "unmask": boolean }

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.

endTime

The end of the time range, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a timestamp equal to or later than this time are not included.

Type: Long

Valid Range: Minimum value of 0.

Required: No

limit

The maximum number of log events returned. If you don't specify a limit, the default is as many log events as can fit in a response size of 1 MB (up to 10,000 log events).

Type: Integer

Valid Range: Minimum value of 1. Maximum value of 10000.

Required: No

logGroupIdentifier

Specify either the name or ARN of the log group to view events from. If the log group is in a source account and you are using a monitoring account, you must use the log group ARN.

Note

You must include either logGroupIdentifier or logGroupName, but not both.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 2048.

Pattern: [\w#+=/:,.@-]*

Required: No

logGroupName

The name of the log group.

Note

You must include either logGroupIdentifier or logGroupName, but not both.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 512.

Pattern: [\.\-_/#A-Za-z0-9]+

Required: No

logStreamName

The name of the log stream.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 512.

Pattern: [^:*]*

Required: Yes

nextToken

The token for the next set of items to return. (You received this token from a previous call.)

Type: String

Length Constraints: Minimum length of 1.

Required: No

startFromHead

If the value is true, the earliest log events are returned first. If the value is false, the latest log events are returned first. The default value is false.

If you are using a previous nextForwardToken value as the nextToken in this operation, you must specify true for startFromHead.

Type: Boolean

Required: No

startTime

The start of the time range, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a timestamp equal to this time or later than this time are included. Events with a timestamp earlier than this time are not included.

Type: Long

Valid Range: Minimum value of 0.

Required: No

unmask

Specify true to display the log event fields with all sensitive data unmasked and visible. The default is false.

To use this operation with this parameter, you must be signed into an account with the logs:Unmask permission.

Type: Boolean

Required: No

Response Syntax

{ "events": [ { "ingestionTime": number, "message": "string", "timestamp": number } ], "nextBackwardToken": "string", "nextForwardToken": "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.

events

The events.

Type: Array of OutputLogEvent objects

nextBackwardToken

The token for the next set of items in the backward direction. The token expires after 24 hours. This token is not null. If you have reached the end of the stream, it returns the same token you passed in.

Type: String

Length Constraints: Minimum length of 1.

nextForwardToken

The token for the next set of items in the forward direction. The token expires after 24 hours. If you have reached the end of the stream, it returns the same token you passed in.

Type: String

Length Constraints: Minimum length of 1.

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

Examples

To list all the events for a log stream

The following example lists all events for the specified log stream.

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.GetLogEvents { "logGroupName": "my-log-group", "logStreamName": "my-log-stream" }

Sample Response

HTTP/1.1 200 OK x-amzn-RequestId: <RequestId> Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Date: <Date> { "events": [ { "ingestionTime": 1396035394997, "timestamp": 1396035378988, "message": "Example event 1" }, { "ingestionTime": 1396035394997, "timestamp": 1396035378988, "message": "Example event 2" }, { "ingestionTime": 1396035394997, "timestamp": 1396035378989, "message": "Example event 3" } ], "nextBackwardToken": "b/31132629274945519779805322857203735586714454643391594505", "nextForwardToken": "f/31132629323784151764587387538205132201699397759403884544" }

Example

The following example lists all events for the specified log stream.

Sample Request

{ "logGroupIdentifier": "arn:aws:logs:us-east-1:123456789012:log-group:monitoring-logGroup-1234:*", "logStreamName": "my-log-stream" }

Sample Response

{ "events": [ { "ingestionTime": 1396035394997, "timestamp": 1396035378988, "message": "Example event 1" }, { "ingestionTime": 1396035394997, "timestamp": 1396035378988, "message": "Example event 2" }, { "ingestionTime": 1396035394997, "timestamp": 1396035378989, "message": "Example event 3" } ], "nextBackwardToken": "b/31132629274945519779805322857203735586714454643391594505", "nextForwardToken": "f/31132629323784151764587387538205132201699397759403884544" }

See Also

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