Created
September 2, 2025 10:33
-
-
Save saahityaedams/1bb63e45b87cdcfc7cd19591a8f56051 to your computer and use it in GitHub Desktop.
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 | |
| 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