AWS SES exporting the suppression list as a CSV via the command line

~ 2 min read


  • AWS CLI is installed
  • Your AWS access key and secret configured as a profile in ~/.aws/credentials
  • jq cli is installed

Retrieveing the suppression list from AWS

In the following:

  • {profile} should be replaced with the profile name you want to use from your ~/.aws/credentials file
  • {region} should be replaced with the region name your SES suppression list is in

The following command line queries AWS for the suppression list in pages, the first call to aws does not need a --next-token="..." param but if the results fetched by the first call return a “next token” at the end of the file, then each subsequent call needs the next token specifying via the --next-token="..." param to page through the results until no token is returned.

aws --profile={profile} \
   --region={region} \
   sesv2 list-suppressed-destinations \
   --page-size=1000 \
   --next-token="..." \ # first call/page omitt this param
# repeat above for each next token incrementing number in filename until no token is returned

NOTE: output is sent to suppressed1.json first call, then replace with suppressed2.json if you need a second page etc..

Filtering and converting the JSON output of AWS CLI to CSV using jq

NOTE: suppressed?.json expands to match all matching files with a single character wild card where the question mark is.

jq '.SuppressedDestinationSummaries[] | [.EmailAddress, .Reason, .LastUpdateTime] | @csv' \ 
   <suppressed?.json >suppressed.csv 

The final CSV is written into suppressed.csv but is quoted a bit strange as each line is a double-quoted string with the escaped double-quoted CSV within that quoted line.

all posts →