PutLogEvents - Amazon CloudWatch Logs

PutLogEvents

Uploads a batch of log events to the specified log stream.

Important

The sequence token is now ignored in PutLogEvents actions. PutLogEvents actions are always accepted and never return InvalidSequenceTokenException or DataAlreadyAcceptedException even if the sequence token is not valid. You can use parallel PutLogEvents actions on the same log stream.

The batch of events must satisfy the following constraints:

  • The maximum batch size is 1,048,576 bytes. This size is calculated as the sum of all event messages in UTF-8, plus 26 bytes for each log event.

  • None of the log events in the batch can be more than 2 hours in the future.

  • None of the log events in the batch can be more than 14 days in the past. Also, none of the log events can be from earlier than the retention period of the log group.

  • The log events in the batch must be in chronological order by their timestamp. The timestamp is the time that the event occurred, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. (In AWS Tools for PowerShell and the AWS SDK for .NET, the timestamp is specified in .NET format: yyyy-mm-ddThh:mm:ss. For example, 2017-09-15T13:45:30.)

  • A batch of log events in a single request cannot span more than 24 hours. Otherwise, the operation fails.

  • Each log event can be no larger than 256 KB.

  • The maximum number of log events in a batch is 10,000.

  • Important

    The quota of five requests per second per log stream has been removed. Instead, PutLogEvents actions are throttled based on a per-second per-account quota. You can request an increase to the per-second throttling quota by using the Service Quotas service.

If a call to PutLogEvents returns "UnrecognizedClientException" the most likely cause is a non-valid AWS access key ID or secret key.

Request Syntax

{ "logEvents": [ { "message": "string", "timestamp": number } ], "logGroupName": "string", "logStreamName": "string", "sequenceToken": "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.

logEvents

The log events.

Type: Array of InputLogEvent objects

Array Members: Minimum number of 1 item. Maximum number of 10000 items.

Required: Yes

logGroupName

The name of the log group.

Type: String

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

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

Required: Yes

logStreamName

The name of the log stream.

Type: String

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

Pattern: [^:*]*

Required: Yes

sequenceToken

The sequence token obtained from the response of the previous PutLogEvents call.

Important

The sequenceToken parameter is now ignored in PutLogEvents actions. PutLogEvents actions are now accepted and never return InvalidSequenceTokenException or DataAlreadyAcceptedException even if the sequence token is not valid.

Type: String

Length Constraints: Minimum length of 1.

Required: No

Response Syntax

{ "nextSequenceToken": "string", "rejectedLogEventsInfo": { "expiredLogEventEndIndex": number, "tooNewLogEventStartIndex": number, "tooOldLogEventEndIndex": number } }

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.

nextSequenceToken

The next sequence token.

Important

This field has been deprecated.

The sequence token is now ignored in PutLogEvents actions. PutLogEvents actions are always accepted even if the sequence token is not valid. You can use parallel PutLogEvents actions on the same log stream and you do not need to wait for the response of a previous PutLogEvents action to obtain the nextSequenceToken value.

Type: String

Length Constraints: Minimum length of 1.

rejectedLogEventsInfo

The rejected events.

Type: RejectedLogEventsInfo object

Errors

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

DataAlreadyAcceptedException

The event was already logged.

Important

PutLogEvents actions are now always accepted and never return DataAlreadyAcceptedException regardless of whether a given batch of log events has already been accepted.

HTTP Status Code: 400

InvalidParameterException

A parameter is specified incorrectly.

HTTP Status Code: 400

InvalidSequenceTokenException

The sequence token is not valid. You can get the correct sequence token in the expectedSequenceToken field in the InvalidSequenceTokenException message.

Important

PutLogEvents actions are now always accepted and never return InvalidSequenceTokenException regardless of receiving an invalid sequence token.

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

UnrecognizedClientException

The most likely cause is an AWS access key ID or secret key that's not valid.

HTTP Status Code: 400

Examples

To upload log events into a log stream

The following example uploads the specified log events to 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.PutLogEvents { "logGroupName": "my-log-group", "logStreamName": "my-log-stream", "logEvents": [ { "timestamp": 1396035378988, "message": "Example event 1" }, { "timestamp": 1396035378988, "message": "Example event 2" }, { "timestamp": 1396035378989, "message": "Example event 3" } ] }

Sample Response

HTTP/1.1 200 OK x-amzn-RequestId: <RequestId> Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Date: <Date> { "nextSequenceToken": "49536701251539826331025683274032969384950891766572122113" }

See Also

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