Skip to content

Instantly share code, notes, and snippets.

@developerck
Last active May 15, 2023 06:40
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 developerck/43ca9db1099fbea718913155bfecf2e5 to your computer and use it in GitHub Desktop.
Save developerck/43ca9db1099fbea718913155bfecf2e5 to your computer and use it in GitHub Desktop.
add email to ses supression list to avoid next bounce, subscribe this lambda on bounce notification

Add email into SES suppression list through lambda function , hooked on ses bounce SNS

import json
import boto3
def lambda_handler(event, context):
# TODO implement
status = False
email=''
try :
message = event['Records'][0]['Sns']['Message']
message = json.loads(message);
print("custom logs")
print(message)
if (message['notificationType'] == 'Bounce'):
rec = message['bounce']['bouncedRecipients']
email = rec[0]['emailAddress'];
print(email);
ses = boto3.client('sesv2')
if(email):
response = ses.put_suppressed_destination(
EmailAddress=email,
Reason='BOUNCE'
)
status = True
except Exception as e:
print(e)
return {
'status' : status,
'statusCode': 200,
'body': email
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment