建立多層級主題
市議會請 Sam 為每個部門建立「critical」與「extreme」兩種主題。
「critical」主題會對員工與經理發出警示。
「extreme」主題會對民代與主管發出警示——代表門檻已被完全超越。
例如,清潔隊部門會有 trash_critical 與 trash_extreme 兩個主題。
她已經在變數 sns 中建立好 boto3 的 SNS 用戶端。她也建立了變數 departments,其中包含一份不重複的部門清單。
在這一課中,你要協助 Sam 讓城市運作更有效率!
你將為不同門檻建立多層級主題,並配上不同的訂閱者組合以觸發通知。
你等於是在打造一個智慧警示系統!
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 對每個部門建立一個 critical 主題,並存入
critical。 - 對每個部門建立一個 extreme 主題,並存入
extreme。 - 將建立好的
TopicArns放入dept_arns。 - 列印該字典。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
dept_arns = {}
for dept in departments:
# For each deparment, create a critical topic
critical = sns.____(Name="{}_critical".____(dept))
# For each department, create an extreme topic
extreme = sns.____(Name="{}_extreme".____(dept))
# Place the created TopicARNs into a dictionary
dept_arns['{}_critical'.____(dept)] = critical['____']
dept_arns['{}_extreme'.____(dept)] = extreme['____']
# Print the filled dictionary.
print(dept_arns)