Here is the code.
import boto3
# Create an SNS client
sns = boto3.client('sns', region_name='us-east-1')
# Create a new SNS topic
response = sns.create_topic(Name='MyTopic')
topic_arn = response['TopicArn']
# Subscribe an email endpoint to the topic
response = sns.subscribe(
TopicArn=topic_arn,
Protocol='email',
Endpoint='[email protected]'
)
print("Topic ARN:", topic_arn)
print("Subscription ARN:", response['SubscriptionArn'])