I am trying to use the AWS CLI and ASK CLI to code an Alexa skill, and I would like to be able to use the Alexa simulator and view the console logs directly from the command line to make it easy, but I am not sure how to view the last one from the command line.
I've installed the AWS and ASK CLI already and am able to view Cloudwatch logs, but there is not a fast way of view the last ones.
You can use aws logs describe-log-streams to get the latest stream name and then aws logs get-log-events to get the log records themselves.
LOG_GROUP=/aws/lambda/[YOUR-LAMBDA-NAME]
LOG_STREAM=`aws logs describe-log-streams --log-group-name $LOG_GROUP --max-items 1 --order-by LastEventTime --descending --query logStreams[].logStreamName --output text | head -n 1`
aws logs get-log-events --log-group-name $LOG_GROUP --log-stream-name $LOG_STREAM --query events[].message --output text
With latest AWS CLI you can also use tail.
aws logs tail $LOG_GROUP --follow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With