Subscribes an endpoint to the topic. Some endpoint types, such as email, must be confirmed before their subscriptions are active. When a subscription is not confirmed, its Amazon Resource Number (ARN) is set to 'PendingConfirmation'. :param topic: The topic
(topic, protocol, endpoint)
| 85 | # snippet-start:[python.example_code.sns.Subscribe] |
| 86 | @staticmethod |
| 87 | def subscribe(topic, protocol, endpoint): |
| 88 | """ |
| 89 | Subscribes an endpoint to the topic. Some endpoint types, such as email, |
| 90 | must be confirmed before their subscriptions are active. When a subscription |
| 91 | is not confirmed, its Amazon Resource Number (ARN) is set to |
| 92 | 'PendingConfirmation'. |
| 93 | |
| 94 | :param topic: The topic to subscribe to. |
| 95 | :param protocol: The protocol of the endpoint, such as 'sms' or 'email'. |
| 96 | :param endpoint: The endpoint that receives messages, such as a phone number |
| 97 | (in E.164 format) for SMS messages, or an email address for |
| 98 | email messages. |
| 99 | :return: The newly added subscription. |
| 100 | """ |
| 101 | try: |
| 102 | subscription = topic.subscribe( |
| 103 | Protocol=protocol, Endpoint=endpoint, ReturnSubscriptionArn=True |
| 104 | ) |
| 105 | logger.info("Subscribed %s %s to topic %s.", protocol, endpoint, topic.arn) |
| 106 | except ClientError: |
| 107 | logger.exception( |
| 108 | "Couldn't subscribe %s %s to topic %s.", protocol, endpoint, topic.arn |
| 109 | ) |
| 110 | raise |
| 111 | else: |
| 112 | return subscription |
| 113 | |
| 114 | # snippet-end:[python.example_code.sns.Subscribe] |
| 115 |
no outgoing calls