開始使用免費開始

發送警示

Elena Block 是 Sam 的老朋友,也是市議會成員,正要參選公職。她所在選區對坑洞問題非常在意。她想幫忙解決。

Pothole

Elena 請 Sam 調整 streets_critical topic,當待修補的坑洞清單超過 100 個時就發送警示。

Sam 已在變數 sns 中建立了 boto3 的 SNS 用戶端。她也把 streets_critical 的 topic ARN 存在變數 str_critical_arn 中。

幫 Sam 往下一步前進。

她需要先檢查目前的待辦清單數量,只有在超過 100 時才發送訊息。

第 12 區的命運,以及 Elena 的選舉結果,就靠你和 Sam 了。

本練習屬於課程

Python 中的 AWS Boto 入門

檢視課程

練習說明

  • 如果坑洞超過 100 個,請以目前的待辦清單數量發送訊息。
  • 建立電子郵件主旨時,也要包含目前的待辦清單數量。
  • 將訊息發佈到 streets_critical 的 Topic ARN。

動手互動練習

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

# If there are over 100 potholes, create a message
if streets_v_count > 100:
  # The message should contain the number of potholes.
  message = "There are {} potholes!".____(streets_v_count)
  # The email subject should also contain number of potholes
  subject = "Latest pothole count is {}".____(streets_v_count)

  # Publish the email to the streets_critical topic
  sns.____(
    ____ = str_critical_arn,
    # Set subject and message
    ____ = ____,
    ____ = ____
  )
編輯並執行程式碼