2015-12-30 54 views
3

我有一個PHP工作人員,我在AWS上記錄事件可以觀看。 不幸的是,當我嘗試提交時出現以下錯誤。AWS-CloudWatch:InvalidSequenceTokenException

InvalidSequenceTokenException Error executing "PutLogEvents" on " https://logs.eu-west-1.amazonaws.com "; AWS HTTP error: Client error: POST https://logs.eu-west-1.amazonaws.com resulted in a 400 Bad Request response: {"__type":"InvalidSequenceTokenException","expectedSequenceToken":"999999999999990356407851919528174 (truncated...) InvalidSequenceTokenException (client): The given sequenceToken is invalid. The next expected sequenceToken is: 495599999999988500356407851919528174642 - {"__type":"InvalidSequenceTokenException","expectedSequenceToken":"495573099999999900356407851919528174642","message":"The given sequenceToken is invalid. The next expected sequenceToken is: 495579999999900356407851919528174642"}

,這是我的代碼

$date = new DateTime(); 
$instance= = new CloudWatchLogsClient([ 
       'region' => 'eu-west-1', 
       'version' => 'latest', 
       'credentials' => [ 
        'key' => 'XXX', 
        'secret' => 'XXXX' 
       ] 
      ]); 
     $instance->putLogEvents([ 
       'logGroupName' => "WorkerLog", 
       'logStreamName' => "log", 
       'logEvents' => [ 
        [ 
         'timestamp' => $date->getTimestamp(), 
         'message' => "test log" 
        ] 
       ] 
      ]); 

回答

4

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

必須包括與您的請求次序令牌。如果您沒有,您必須使用describeLogStreams(http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogStreams.html)來獲取流序列。

當你打電話給putLogEvents時,你會在響應中得到nextToken。您還必須爲其他人推送流並使nextToken無效的情況做好準備。 (在這種情況下,您需要再次描述流以獲取更新的令牌)。

+0

謝謝你是對的。但調用describeLogStream不會返回下一個序列!請更新您的答案,以便我可以接受它。它實際上是 – Moussawi7

+0

。我看你的迴應,它包含一個LogStreams對象的數組:http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_LogStream.html UploadSequenceToken在響應中是你需要傳入的。 – Mircea

+0

謝謝@thext,你是完全正確的。 – Moussawi7