I have a lambda function which sends mail and returns the MessageID
as output if the email was sent successfully, error message if it fails. Now I want to create an architecture where this returned email status will be saved in an SNS topic. There will be another Lambda function as subscriber which will be triggered by the Email status of the SNS topic.
Example: If the publisher Lambda returns MessageID, the subscriber Lambda will return "yes", "no" for error message. Is it possible to achieve? If not, what is the closest can I go?
What I have done so far
- Created an SNS Topic
- Created a subscriber Lambda function for the topic. Added trigger for the following SNS topic in the Lambda.
- Added SNS client in my existing Lambda which I want to use as publisher. This Lambda returns the MessageID if mail is sent successfully.
- I published a simple message to the specified SNS topic.
Here is code of subscriber function following the docs :
import json
def lambda_handler(event, context):
# TODO implement
return {
# 'statusCode': 200,
# 'body': json.dumps('Hello from Lambda!')
message = json.loads(event['Records'][0]['Sns']['Message'])
print("JSON: " + json.dumps(message))
return message
}
My code for publishing message to SNS topic:
sns_client = boto3.client('sns', aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY, region_name=AWS_REGION)
sns_response = sns_client.publish(
TopicArn='my-ARN',
Message='Hello World',
)