Skip to content

Instantly share code, notes, and snippets.

@cam8001
Created September 15, 2022 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cam8001/f1664f706e724b630db2879853ae5e12 to your computer and use it in GitHub Desktop.
Save cam8001/f1664f706e724b630db2879853ae5e12 to your computer and use it in GitHub Desktop.
Export a contact list from SES, with pagination
#!/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