def _set_topic_subs(self):
    changed = False
    subscriptions_existing_list = set()
    desired_subscriptions = [(sub['protocol'], self._canonicalize_endpoint(sub['protocol'], sub['endpoint'])) for sub in self.subscriptions]
    for sub in self._list_topic_subscriptions():
        sub_key = (sub['Protocol'], sub['Endpoint'])
        subscriptions_existing_list.add(sub_key)
        if (self.purge_subscriptions and (sub_key not in desired_subscriptions) and (sub['SubscriptionArn'] not in ('PendingConfirmation', 'Deleted'))):
            changed = True
            self.subscriptions_deleted.append(sub_key)
            if (not self.check_mode):
                try:
                    self.connection.unsubscribe(SubscriptionArn=sub['SubscriptionArn'])
                except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
                    self.module.fail_json_aws(e, msg="Couldn't unsubscribe from topic")
    for (protocol, endpoint) in set(desired_subscriptions).difference(subscriptions_existing_list):
        changed = True
        self.subscriptions_added.append((protocol, endpoint))
        if (not self.check_mode):
            try:
                self.connection.subscribe(TopicArn=self.topic_arn, Protocol=protocol, Endpoint=endpoint)
            except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
                self.module.fail_json_aws(e, msg=("Couldn't subscribe to topic %s" % self.topic_arn))
    return changed
def _set_topic_subs(self):
    changed = False
    subscriptions_existing_list = set()
    desired_subscriptions = [(sub['protocol'], self._canonicalize_endpoint(sub['protocol'], sub['endpoint'])) for sub in self.subscriptions]
    for sub in self._list_topic_subscriptions():
        sub_key = (sub['Protocol'], sub['Endpoint'])
        subscriptions_existing_list.add(sub_key)
        if (self.purge_subscriptions and (sub_key not in desired_subscriptions) and (sub['SubscriptionArn'] not in ('PendingConfirmation', 'Deleted'))):
            changed = True
            self.subscriptions_deleted.append(sub_key)
            if (not self.check_mode):
                try:
                    self.connection.unsubscribe(SubscriptionArn=sub['SubscriptionArn'])
                except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
                    self.module.fail_json_aws(e, msg="Couldn't unsubscribe from topic")
    for (protocol, endpoint) in set(desired_subscriptions).difference(subscriptions_existing_list):
        changed = True
        self.subscriptions_added.append((protocol, endpoint))
        if (not self.check_mode):
            try:
                self.connection.subscribe(TopicArn=self.topic_arn, Protocol=protocol, Endpoint=endpoint)
            except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
                self.module.fail_json_aws(e, msg=("Couldn't subscribe to topic %s" % self.topic_arn))
    return changed