Last active
July 12, 2016 13:55
-
-
Save ajkerrigan/0fe2a95d043cfab9fead9562fb8a49a5 to your computer and use it in GitHub Desktop.
Get the most recent Cloudwatch log messages for a specified AWS Lambda function (requires the AWS CLI and jq)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Usage: cwlastlog.sh <Lambda function name> | |
| LAMBDA_FUNCTION="${1}" | |
| MESSAGE_LIMIT=50 | |
| # Get the name of the log stream with the most recent activity for this log group | |
| LAST_LOG_STREAM=`aws logs describe-log-streams --log-group-name "/aws/lambda/${LAMBDA_FUNCTION}" \ | |
| --descending --order-by LastEventTime --max-items 1 | jq --raw-output '.logStreams[0].logStreamName'` | |
| aws logs get-log-events --log-group-name "/aws/lambda/${LAMBDA_FUNCTION}" \ | |
| --log-stream-name "${LAST_LOG_STREAM}" --limit "${MESSAGE_LIMIT}" | jq --raw-output --slurp '..|.message?' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment