Created
September 15, 2022 00:18
-
-
Save cam8001/f1664f706e724b630db2879853ae5e12 to your computer and use it in GitHub Desktop.
Export a contact list from SES, with pagination
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 | |
# Specify contact list name here | |
CONTACT_LIST_NAME='' | |
OUTPUT_FILE="./contact-list_$CONTACT_LIST_NAME-$(date +%s).csv" | |
AWS_CLI_COMMAND="aws sesv2 list-contacts --contact-list-name $CONTACT_LIST_NAME --filter FilteredStatus=OPT_IN --page-size 1000 " | |
function cli_call() { | |
if [ ! -z NEXT_TOKEN ]; then | |
cli_output=$($AWS_CLI_COMMAND) | |
else | |
cli_output=$($AWS_CLI_COMMAND --next-token $NEXT_TOKEN) | |
fi | |
## Pipe output to our specified output file | |
echo $cli_output >> $OUTPUT_FILE | |
# If there is a next token, it will be returned from this function | |
echo $cli_output | jq -r ".NextToken" | |
} | |
while [ "$NEXT_TOKEN" != "null" ]; do | |
NEXT_TOKEN=$(CLI_call $NEXT_TOKEN) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment