Created
August 1, 2025 11:30
-
-
Save erikologic/e313958bb130ecaf278770e3389189a8 to your computer and use it in GitHub Desktop.
AWS tools
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 | |
| set -eo pipefail | |
| AWS_PARAMS=("$@") | |
| NEXT_TOKEN="" | |
| OUTPUT="{}" | |
| deep_merge() { | |
| jq -s ' | |
| def meld(a; b): | |
| a as $a | b as $b | |
| | if ($a|type) == "object" and ($b|type) == "object" | |
| then reduce ([$a,$b]|add|keys_unsorted[]) as $k ({}; | |
| .[$k] = meld( $a[$k]; $b[$k]) ) | |
| elif ($a|type) == "array" and ($b|type) == "array" | |
| then $a+$b | |
| elif $b == null then $a | |
| else $b | |
| end; | |
| meld(.[0]; .[1]) | |
| ' "$1" "$2" | |
| } | |
| while [ "$NEXT_TOKEN" != "null" ]; do | |
| MY_PARAMS=("${AWS_PARAMS[@]}") | |
| if [ -n "$NEXT_TOKEN" ]; then | |
| MY_PARAMS+=(--next-token "$NEXT_TOKEN") | |
| fi | |
| RESPONSE=$(aws "${MY_PARAMS[@]}" --output json) | |
| OUTPUT=$(deep_merge <(echo "$OUTPUT") <(echo "$RESPONSE")) | |
| NEXT_TOKEN=$(echo "$RESPONSE" | jq -r '.nextToken // "null"') | |
| done | |
| echo "$OUTPUT" | jq 'del(.nextToken)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aws_unpaginated.sh --> a script that will proxy AWS CLI calls to automatically loop through paginated response until the end of the list