Last active
July 9, 2020 20:43
-
-
Save justmiles/969a92102e458e99eee6952ee88acfcb to your computer and use it in GitHub Desktop.
This file contains 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-paginated | |
# usage: aws-paginated <any aws cli command> | |
# requirements: aws-cli, jq | |
# | |
function aws-paginated() { | |
AWS_CLI_COMMAND="${@}" | |
OUTPUT=$(mktemp) | |
function _invoke() { | |
TMP_OUTPUT=$(mktemp) | |
if [ -z "$NEXT_TOKEN" ]; then | |
eval "aws $AWS_CLI_COMMAND --output json" >$TMP_OUTPUT | |
else | |
eval "aws $AWS_CLI_COMMAND --output json --next-token '$NEXT_TOKEN'" >$TMP_OUTPUT | |
fi | |
cat $TMP_OUTPUT | jq -c 'del(.NextToken)' >>$OUTPUT | |
jq -r ".NextToken" $TMP_OUTPUT | |
} | |
NEXT_TOKEN=$(_invoke $NEXT_TOKEN) | |
while [ ! -z "$NEXT_TOKEN" ]; do | |
NEXT_TOKEN=$(_invoke $NEXT_TOKEN) | |
done | |
cat $OUTPUT | jq -s '{PaginatedResults: .}' | |
rm -rf $OUTPUT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment