Skip to content

Instantly share code, notes, and snippets.

@hmit208
Forked from jsyi/cwl-last-used.sh
Created October 27, 2022 06:40
Show Gist options
  • Select an option

  • Save hmit208/c09365ea2758d044ec81f598c291d6b9 to your computer and use it in GitHub Desktop.

Select an option

Save hmit208/c09365ea2758d044ec81f598c291d6b9 to your computer and use it in GitHub Desktop.
Use AWS CLI to query AWS CloudWatch Logs and determine the most recent entry into a Log Group
aws logs describe-log-groups | jq ".logGroups[].logGroupName" | grep -E "homeplus|mcdonalds" | xargs -n 1 -t aws logs describe-log-streams --query "logStreams[*].lastEventTimestamp" --log-group | jq "max/1000|floor" | xargs -t -n 1 date -r
# aws logs describe-log-groups | jq ".logGroups[].logGroupName"
# Get LogGroup names
# grep -E "homeplus|mcdonalds"
# (Optional) Filter LogGroup names
# xargs -n 1 -t aws logs describe-log-streams --query "logStreams[*].lastEventTimestamp" --log-group | jq "max/1000|floor"
# Get last event timestamp for each LogGroup.
# (Optional) Convert milliseconds timestamp to seconds timestamp.
# xargs -t -n 1 date -r
# (MacOS X) Format seconds timestamp into human-readable format.
# (Other) Change `date -r` to `date -d` or other option appropriate to the installation of `date` included with your OS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment