You can download this code by clicking the button below.
This code is now available for download.
This function uses the boto3 library and sns module to create a random SNS (Simple Notification Service) topic and returns the ARN (Amazon Resource Name) of the topic. The function creates a unique topic by using random selection of topic names.
Technology Stack : boto3, boto3.client, boto3.sns, random.choice
Code Type : Function
Code Difficulty : Intermediate
import boto3
import random
def generate_random_sns_topic_name():
sns = boto3.client('sns')
response = sns.create_topic(Name=random.choice(['Topic1', 'Topic2', 'Topic3', 'Topic4', 'Topic5']))
return response['TopicArn']