AWS SES exporting the suppression list as a CSV using GO Lang

~ 2 min read


  • Go Lang is installed on your computer
  • Your AWS access key and secret configured as a profile in ~/.aws/credentials

Writing the code

Create a directory for the code, in it create a file called awsSesGetSuppressionList.go and paste in the following code. You may choose to change the hard coded AWS Region and AWS profile or set them to blank strings, so they can be set via environment variables of AWS_REGION and AWS_PROFILE respectively.

package main

import (

func main() {
	// Initialize a session in eu-west-2 that the SDK will use to load
	// credentials from the shared credentials file ~/.aws/credentials.
	sess, err := session.NewSession(&aws.Config{
		Region:      aws.String("eu-west-2"),                         // Or leave blank and specify with env AWS_REGION=
		Credentials: credentials.NewSharedCredentials("", "default"), // Or leave blank and specify with env AWS_PROFILE=

	// Create SESv2 service client
	client := sesv2.New(sess)

	// Example iterating over at most 2 pages of a ListSuppressedDestinations operation.
	pageNum := 0
	params := sesv2.ListSuppressedDestinationsInput{}
	w := csv.NewWriter(os.Stdout)
	err = w.Write([]string{"email", "reason", "datetime"})
	err = client.ListSuppressedDestinationsPages(&params,
		func(page *sesv2.ListSuppressedDestinationsOutput, lastPage bool) bool {
			for _, value := range page.SuppressedDestinationSummaries {
				email, reason, updated := *value.EmailAddress, *value.Reason, *value.LastUpdateTime
				row := []string{email, reason, updated.String()}
				if err := w.Write(row); err != nil {
					log.Fatalln("error writing record to csv:", err)
			return lastPage == false

	if err != nil {

	// Write any buffered data to the underlying writer (standard output).

	if err := w.Error(); err != nil {

Then on the command line in the same directory as the code run go build and you should have a binary executable file in the same directory called awsSesGetSuppressionList i.e. no file extension.

Retrieving the suppression list from AWS

Open a terminal window in the directory containing your code, then type

AWS_PROFILE=default; AWS_REGION=eu-west-2; ./awsSesGetSuppressionList >suppressed.csv

Which will pull down the suppression list from region eu-west-2 using the default AWS credentials and place the results in the file supressed.csv which can then be imported into the relevant tool to mark emails as undeliverable at source rather than have AWS suppression them.

all posts →