Search code examples
amazon-web-servicesaws-cliamazon-cloudwatchamazon-cloudwatchlogs

How do I write logs to cloudwatch using aws-cli?


i'm trying to write a log to cloudwatch (just to understand how it works)

so from the aws-cli (already configured) i'm issuing this command

aws logs put-log-events --log-group-name testgroup --log-stream-name teststream1 --log-events timestamp=1587488538,message=hello

on cloudwatch the group-name and the stream-log already exist and the the names are correct

the output of the command is the following

{ "rejectedLogEventsInfo": { "tooOldLogEventEndIndex": 1 } }

the user i'm using has the "AdministratorAccess" policy attached (and to be sure i've added "CloudWatchFullAccess" policy as well)


Solution

  • You need to convert your timestamp to milliseconds version (multiply with 1000 in your case)

    aws logs put-log-events --log-group-name testgroup --log-stream-name teststream1 --log-events timestamp=1587488538000,message=hello
    

    please check AWS CLI examples