Cloudwatch boto3 put_log_events giving incorrect return

4.7k views Asked by At

I'm using boto3 to post log events from some code. The results show that 0 bytes are stored - everything else appears valid, the next sequenceToken and the creationtime - but there are no events in the log. The message I'm sending is just a simple message = "test". It appears when I call this function though, unexpected results of the logstream type are returned. Anyone know what might be causing this?

 kwargs = {'logGroupName': self.log_group_name,
           'logStreamName': self.log_stream_name,
           'logEvents': [
                    {
                        'timestamp': ts,
                        'message': message
                    },
                ]}

        token = self.get_seq_token()
        if token:
            print 'token:' + token
            kwargs.update({'sequenceToken': token})

        response = self.client.put_log_events(**kwargs) 

Results seem to be a log stream:

{'storedBytes': 0, 'creationTime': 1481640079355, 
'uploadSequenceToken': 'validtoken', 
'logStreamName': 'test_stream_1', 
'lastIngestionTime': 1481640079447, 
'arn': 'arn:aws:logs:us-east-1:[aws_id]:log-group:test_group:log-stream:test_stream_1'}

From the documentation was expecting:

{
    'nextSequenceToken': 'string',
    'rejectedLogEventsInfo': {
        'tooNewLogEventStartIndex': 123,
        'tooOldLogEventEndIndex': 123,
        'expiredLogEventEndIndex': 123
    }
}
1

There are 1 answers

0
WalterVonBruegemon On

The incorrect result was a red herring- the error was that the time was too long ago.Need to multiply unix time by 1000

 ts = int(time.time()*1000)

Related to this: amazon CloudWatchLogs putLogEvents