Skip to content

Instantly share code, notes, and snippets.

@saahityaedams
Created September 2, 2025 10:33
Show Gist options
  • Select an option

  • Save saahityaedams/1bb63e45b87cdcfc7cd19591a8f56051 to your computer and use it in GitHub Desktop.

Select an option

Save saahityaedams/1bb63e45b87cdcfc7cd19591a8f56051 to your computer and use it in GitHub Desktop.
#!/bin/bash
AWS_PROFILE="example-profile"
LOG_GROUP="/ecs/example-task"
LOG_STREAM="ecs/container/abcdef1234567890"
FILE="logs.txt"
> "$FILE"
TOKEN=""
while : ; do
if [ -z "$TOKEN" ]; then
RESPONSE=$(aws logs get-log-events \
--profile "$AWS_PROFILE" \
--log-group-name "$LOG_GROUP" \
--log-stream-name "$LOG_STREAM" \
--start-from-head \
--limit 10000 \
--output json)
else
RESPONSE=$(aws logs get-log-events \
--profile "$AWS_PROFILE" \
--log-group-name "$LOG_GROUP" \
--log-stream-name "$LOG_STREAM" \
--next-token "$TOKEN" \
--limit 10000 \
--output json)
fi
echo "$RESPONSE" | jq -r '.events[] | "\(.timestamp): \(.message)"' >> "$FILE"
NEXT_TOKEN=$(echo "$RESPONSE" | jq -r '.nextForwardToken')
if [ "$NEXT_TOKEN" == "$TOKEN" ] || [ "$NEXT_TOKEN" == "null" ]; then
break
fi
TOKEN="$NEXT_TOKEN"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment