PutLogEvents
Uploads a batch of log events to the specified log stream.
You must include the sequence token obtained from the response of the previous call. An
upload in a newly created log stream does not require a sequence token. You can also get the
sequence token in the expectedSequenceToken
field from
InvalidSequenceTokenException
. If you call PutLogEvents
twice
within a narrow time period using the same value for sequenceToken
, both calls
might be successful or one might be rejected.
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 older than 14 days or older 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 the event occurred, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. (In Amazon Tools for PowerShell and the Amazon 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.
-
The maximum number of log events in a batch is 10,000.
-
There is a quota of 5 requests per second per log stream. Additional requests are throttled. This quota can't be changed.
If a call to PutLogEvents
returns "UnrecognizedClientException" the most likely cause is an invalid Amazon 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. An upload in a newly created log stream does not require a sequence token. You can also get the sequence token using DescribeLogStreams. If you callPutLogEvents
twice within a narrow time period using the same value forsequenceToken
, both calls might be successful or one might be rejected.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.
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.
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 theInvalidSequenceTokenException
message.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 invalid Amazon access key ID or secret key.
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 Amazon SDKs, see the following: