Skip to content

Instantly share code, notes, and snippets.

@ajkerrigan
Last active July 12, 2016 13:55
Show Gist options
  • Select an option

  • Save ajkerrigan/0fe2a95d043cfab9fead9562fb8a49a5 to your computer and use it in GitHub Desktop.

Select an option

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)
#!/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