In this Lab, we will invoke an API configured through API Gateway.
API will in turn invoke the Lambda function, which will trigger an SNS Email Notification.
API Gateway
Lambda Function
Simple Notification Service (SNS)
learnpde@gmail.com
API-Lambda-SNS-Integration
import boto3
def lambda_handler(event, context):
# Initialize SNS client
sns = boto3.client('sns')
# Specify your SNS topic ARN
topic_arn = 'arn:aws:sns:us-east-1:211125437318:MyTopic'
# Publish a message to the SNS topic
sns.publish(
TopicArn=topic_arn,
Message='Hello from Lambda! This is the message that will be sent in the email.',
Subject='Email Subject from Lambda'
)
return {
'statusCode': 200,
'body': 'Message published to SNS topic successfully!'
}