Last active
May 15, 2023 06:40
-
-
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
This file contains 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
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