Skip to content

Instantly share code, notes, and snippets.

@sasasin
Created March 9, 2023 03:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasasin/a32e065e5117b184ec5681731dbcd065 to your computer and use it in GitHub Desktop.
Save sasasin/a32e065e5117b184ec5681731dbcd065 to your computer and use it in GitHub Desktop.
AWS CLI の任意のコマンドを実行して .NextToken を追い掛けて全部取るやつ
#!/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 ""
@sasasin
Copy link
Author

sasasin commented Mar 9, 2023

next-token によるページネートで追い掛けが必要なコマンドを、そっくりそのまま渡して、

./aws-cli-exec-with-next-token.sh aws synthetics describe-canaries

などのように使う

@sasasin
Copy link
Author

sasasin commented Mar 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment