Get startedGet started for free

Deleting multiple subscriptions

Now that Sam has a maturing notification system, she is learning that the types of alerts she sends do not bode well for text messaging.

SMS alerts are great if the user can react that minute, but "We are 500 potholes behind" is not something that a Council Member can jump up and fix.

She decides to remove all SMS subscribers from the streets_critical topic, but keep all email subscriptions.

She created the boto3 SNS client in the sns variable, and the streets_critical topic ARN is in the str_critical_arn variable.

In this exercise, you will help Sam remove all SMS subscribers and make this an email only alerting system.

This exercise is part of the course

Introduction to AWS Boto in Python

View Course

Exercise instructions

  • List subscriptions for 'streets_critical' topic.
  • For each subscription, if the protocol is 'sms', unsubscribe.
  • List subscriptions for 'streets_critical' topic in one line.
  • Print the subscriptions

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# List subscriptions for streets_critical topic.
response = sns.____(
  ____ = str_critical_arn)

# For each subscription, if the protocol is SMS, unsubscribe
for sub in response['____']:
  if sub['Protocol'] == 'sms':
	  sns.____(____=sub['SubscriptionArn'])

# List subscriptions for streets_critical topic in one line
subs = sns.list_subscriptions_by_topic(
  ____=str_critical_arn)['____']

# Print the subscriptions
print(subs)
Edit and Run Code