(self)
return queue
Get or create the SQS queue. If it is created, then it is
        also subscribed to the SNS topic, and a policy is set to allow
        the SNS topic to send messages to the queue.
Get or create the SQS queue. If it is created, then it is
        also subscribed to the SNS topic, and a policy is set to allow
        the SNS topic to send messages to the queue.
Get or create the SQS queue . If it is created then it is also subscribed to the SNS topic and a policy is set to allow the SNS topic to send messages to the queue .
def get_sqs_queue(self):
        """
        Get or create the SQS queue. If it is created, then it is
        also subscribed to the SNS topic, and a policy is set to allow
        the SNS topic to send messages to the queue.
        """
        # Creating a queue is idempotent, so if it already exists
        # then we will just get the queue returned.
        queue = self.sqs.create_queue(QueueName=self.queue_name)
        self.queue_arn = queue.attributes['QueueArn']

        # Ensure that we are subscribed to the SNS topic
        subscribed = False
        topic = self.sns.Topic(self.topic_arn)
        for subscription in topic.subscriptions.all():
            if subscription.attributes['Endpoint'] == self.queue_arn:
                subscribed = True
                break

        if not subscribed:
            topic.subscribe(Protocol='sqs', Endpoint=self.queue_arn)

        # Set up a policy to allow SNS access to the queue
        if 'Policy' in queue.attributes:
            policy = json.loads(queue.attributes['Policy'])
        else:
            policy = {'Version': '2008-10-17'}

        if 'Statement' not in policy:
            statement = self.queue_policy_statement
            statement['Resource'] = self.queue_arn
            statement['Condition']['StringLike']['aws:SourceArn'] = \
                self.topic_arn
            policy['Statement'] = [statement]

            queue.set_attributes(Attributes={
                'Policy': json.dumps(policy)
            })

        return queue
def get_sqs_queue ( self ) : # Creating a queue is idempotent, so if it already exists # then we will just get the queue returned. queue = self . sqs . create_queue ( QueueName = self . queue_name ) self . queue_arn = queue . attributes [ 'QueueArn' ] # Ensure that we are subscribed to the SNS topic subscribed = False topic = self . sns . Topic ( self . topic_arn ) for subscription in topic . subscriptions . all ( ) : if subscription . attributes [ 'Endpoint' ] == self . queue_arn : subscribed = True break if not subscribed : topic . subscribe ( Protocol = 'sqs' , Endpoint = self . queue_arn ) # Set up a policy to allow SNS access to the queue if 'Policy' in queue . attributes : policy = json . loads ( queue . attributes [ 'Policy' ] ) else : policy = { 'Version' : '2008-10-17' } if 'Statement' not in policy : statement = self . queue_policy_statement statement [ 'Resource' ] = self . queue_arn statement [ 'Condition' ] [ 'StringLike' ] [ 'aws:SourceArn' ] = self . topic_arn policy [ 'Statement' ] = [ statement ] queue . set_attributes ( Attributes = { 'Policy' : json . dumps ( policy ) } ) return queue