SNS

 SNS


Amazon SNS is a fully managed messaging service that enables you to decouple microservices, distributed systems, and serverless applications. Here is an example of how to create an SNS topic and subscribe an email address using the AWS SDK for Python (boto3):

python


import boto3


sns_client = boto3.client('sns')


topic_name = 'my-topic'


response = sns_client.create_topic(

    Name=topic_name

)


topic_arn = response['TopicArn']


email_address = 'my-email@example.com'


response = sns_client.subscribe(

    TopicArn=topic_arn,

    Protocol='email',

    Endpoint=email_address

)


subscription_arn = response['SubscriptionArn']


print(f"SNS topic {topic_name} created with ARN {topic_arn}")

print(f"Email address {email_address} subscribed to topic with ARN {topic_arn}")

This code creates an SNS topic with the specified name and subscribes an email address to the topic using the create_topic and subscribe methods. The topic ARN and subscription ARN are printed to the console.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...