Created
March 9, 2023 03:07
-
-
Save sasasin/a32e065e5117b184ec5681731dbcd065 to your computer and use it in GitHub Desktop.
AWS CLI の任意のコマンドを実行して .NextToken を追い掛けて全部取るやつ
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 | |
# https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-pagination.html | |
AWS_CLI_COMMAND=$@ | |
aws-cli-exec-with-next-token() | |
{ | |
NEXT_TOKEN="$1" | |
if [ "${NEXT_TOKEN}" == "" ]; then | |
RESPONSE=$( | |
${AWS_CLI_COMMAND} | |
) | |
else | |
RESPONSE=$( | |
${AWS_CLI_COMMAND} \ | |
--next-token "${NEXT_TOKEN}" | |
) | |
fi | |
echo "${RESPONSE}" | |
NEXT_TOKEN=$(echo "${RESPONSE}" | jq -r '.NextToken') | |
if [ "${NEXT_TOKEN}" != "null" ]; then | |
aws-cli-exec-with-next-token "${NEXT_TOKEN}" | |
fi | |
} | |
aws-cli-exec-with-next-token "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aws xxxx list-xxxx
aws xxxx get-xxxx
aws xxxx describe-xxxx
などなど情報取得系で --next-token によるページネートがあるようだ
https://www.google.com/search?q=site://https://awscli.amazonaws.com/v2/documentation/api/latest/reference/+next-token