시작하기무료로 시작하기

토픽 수준별로 서로 다른 프로토콜 사용

이제 Sam이 중요(critical)과 긴급(extreme) 토픽을 만들었으니, 연락처 목록의 직원들을 해당 토픽에 구독시켜야 해요.

Sam은 'critical' 토픽 구독자는 이메일만 받도록 했어요. 반면에 'extreme' 토픽 구독자는 아주 긴급하므로 SMS를 받도록 했어요.

sns 변수에 boto3 SNS 클라이언트는 이미 만들어 두었어요.

contacts DataFrame에 있는 사용자들을 부서에 따라 이메일 또는 SMS 알림에 구독하도록 Sam을 도와주세요. 이렇게 하면 알맞은 경고가 알맞은 사람에게 도착해 샌디에이고 시의 업무가 더 빠르고 효율적으로 진행돼요!

이 연습은 강의의 일부입니다

Python으로 시작하는 AWS Boto

강의 보기

연습 안내

  • contacts DataFrame의 'Department' 필드를 사용해 토픽 이름을 가져오세요.
  • 해당 토픽 이름을 사용해 사용자의 부서에 대한 criticalextreme TopicArn을 만드세요.
  • 사용자의 이메일 주소를 critical 토픽에 구독시키세요.
  • 사용자의 전화번호를 extreme 토픽에 구독시키세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

for index, user_row in contacts.iterrows():
  # Get topic names for the users's dept
  critical_tname = '{}_critical'.____(user_row['Department'])
  extreme_tname = '{}_extreme'.format(user_row['Department'])
  
  # Get or create the TopicArns for a user's department.
  critical_arn = sns.create_topic(____=critical_tname)['TopicArn']
  extreme_arn = sns.____(Name=extreme_tname)['____']
  
  # Subscribe each users email to the critical Topic
  sns.____(____ = critical_arn, 
                ____='email', ____=user_row['Email'])
  # Subscribe each users phone number for the extreme Topic
  sns.____(____ = extreme_arn, 
                ____='sms', ____=str(user_row['Phone']))
코드 편집 및 실행