Amazon CloudWatchLogs putLogEvents in PHP gives error tooOldLogEventEndIndex

这一生的挚爱 提交于 2019-12-10 12:44:48

问题


hi guys i'm 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 u help me understanding what does mean ["rejectedLogEventsInfo"]=> array(1) { ["tooOldLogEventEndIndex"]=> int(1), I will be very grateful for the help.


回答1:


ok guys i found the solution adding this line instead of time() function of php . following this example cloudWatchLogs.

'timestamp' =>  round(microtime(true) * 1000),

i hope that this can help someone on the future thanks.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/32875451/amazon-cloudwatchlogs-putlogevents-in-php-gives-error-toooldlogeventendindex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!