how to view aws log real time (like tail -f)

后端 未结 11 567
执笔经年
执笔经年 2021-01-31 01:13

I can view the log using the following command.

aws logs get-log-events --log-group-name groupName --log-stream-name streamName --limit 100

wha

11条回答
  •  悲哀的现实
    2021-01-31 01:45

    This is not currently a feature of the CLI since it just exposes the HTTP API for CloudWatch Logs. You could fairly trivially emulate the functionality with a shell script:

    #! /bin/sh
    
    end_time=$(($(date +"%s") * 1000))
    aws logs get-log-events --log-group-name groupName --log-stream-name streamName --end-time $end_time
    
    while :
    do
        start_time=$end_time
        end_time=$(($(date +"%s") * 1000))
        aws logs get-log-events --log-group-name groupName --log-stream-name streamName --start-time $start_time --end-time $end_time
        sleep 1
    done
    

    Disclaimer: this won't work on Windows, and there may be a better way to get the time in milliseconds.

提交回复
热议问题