Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon CloudWatchLogs putLogEvents in PHP gives error tooOldLogEventEndIndex

I am trying to put Log on amazon CloudWatchLogs like this:

$response2 = $amzonLoger->putLogEvents([

            'logGroupName' => 'myGroup',
            'logStreamName' => 'myStream',
            'logEvents' => [
                [
                    'timestamp' => time(),
                    'message' => 'message'
                ],
            ],
            'sequenceToken' => lastToken,
        ]);
        var_dump($response2);

but always i've this response :

bject(Guzzle\Service\Resource\Model)#289 (2) { ["structure":protected]=> NULL ["data":protected]=> array(2) { ["nextSequenceToken"]=> string(56) "495401145812734324234234236420825819917076850" ["rejectedLogEventsInfo"]=> array(1) { ["tooOldLogEventEndIndex"]=> int(1) } } }

Can you help me understanding what does mean ["rejectedLogEventsInfo"]=> array(1) { ["tooOldLogEventEndIndex"]=> int(1)?

like image 537
irvinstone Avatar asked Sep 30 '15 20:09

irvinstone


People also ask

What is Putlogevents?

PDF. 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.

What is Amazon CloudWatch logs?

CloudWatch Logs enables you to see all of your logs, regardless of their source, as a single and consistent flow of events ordered by time, and you can query them and sort them based on other dimensions, group them by specific fields, create custom computations with a powerful query language, and visualize log data in ...

How do I create AWS stream log?

To create a log group Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Log groups. Choose Actions, and then choose Create log group. Enter a name for the log group, and then choose Create log group.


2 Answers

Cloudwatch API expects timestamp in epoch milliseconds, not seconds. Took me a while to figure that out. Thanks to the PHP snippet above.

like image 134
Heitor Morgado Avatar answered Sep 27 '22 23:09

Heitor Morgado


Your error is telling you that the timestamp you are using is not good.

http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html

From doc:

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 the retention period of the log group.

If using current time and current time is correct you may be in a different time zone (that is more than 2 hours ahead of UTC). Use UTC time for events timestamp.

like image 22
Mircea Avatar answered Sep 27 '22 23:09

Mircea