Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudwatch boto3 put_log_events giving incorrect return

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
    }
}
like image 274
WalterVonBruegemon Avatar asked Dec 14 '22 02:12

WalterVonBruegemon


1 Answers

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

like image 62
WalterVonBruegemon Avatar answered Jan 13 '23 10:01

WalterVonBruegemon