開始使用免費開始

刪除多個訂閱

Sam 的通知系統已逐漸成熟,她發現自己發送的警示類型並不適合以簡訊傳遞。

如果使用者能在當下回應,SMS 警示很有用,但「我們還落後 500 個坑洞未修」並不是市議員能立刻跳起來處理的事。

她決定從 streets_critical 主題中移除所有 SMS 訂閱者,但保留所有電子郵件訂閱。

她已在變數 sns 中建立 boto3 的 SNS 用戶端,而 streets_critical 主題的 ARN 則在變數 str_critical_arn 中。

在這個練習中,你將協助 Sam 移除所有 SMS 訂閱者,讓這成為僅透過電子郵件發送警示的系統。

本練習屬於課程

Python 中的 AWS Boto 入門

檢視課程

練習說明

  • 列出 'streets_critical' 主題的訂閱。
  • 對每個訂閱,若其通訊協定為 'sms',則取消訂閱。
  • 用一行程式碼列出 'streets_critical' 主題的訂閱。
  • 列印這些訂閱

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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)
編輯並執行程式碼