I am working on an app that uses SNS and SQS to publish topics between entities with boto3. The setup is pretty vanilla where one process has subscribed to the topic and is waiting for activity. The second process is just publishing a message to the topic and I'd expect to see that published message arrive to the listening job but nothing ever does. The SQS dashboard shows that are no messages pending or in flight. There are full permissions on both the queue and the topic. I am new to all of this so it is probably something simple.
listening job:
# Create topic
sns_game_topic = sns_client.create_topic(Name='My_Topic')
# Create queue
queue = sqs_client.create_queue(QueueName='My_Queue.fifo', Attributes={'FifoQueue':'true', 'ContentBasedDeduplication': 'true'})
sqs_arn = sqs_client.get_queue_attributes(QueueUrl=queue['QueueUrl'], AttributeNames=['QueueArn'])['Attributes']['QueueArn']
sns_arn = sns_topic['TopicArn']
sns_client.subscribe(TopicArn=sns_arn, Protocol='sqs', Endpoint=sqs_arn)
sending job:
queue = self.sqs_client.create_queue(QueueName='Battleship_Registration.fifo', Attributes={'FifoQueue':'true', 'ContentBasedDeduplication': 'true'})
sqs_arn = self.sqs_client.get_queue_attributes(QueueUrl=queue['QueueUrl'], AttributeNames=['QueueArn'])['Attributes']['QueueArn']
# This topic should already exist but creation is idempotent and we need the arn to subscribe to it
topic = self.sns_client.create_topic(Name='My_Topic')
sns_arn = topic['TopicArn']
# Connect topic to queue
self.sns_client.subscribe(TopicArn=sns_arn, Protocol='sqs', Endpoint=sqs_arn)
pub = self.sns_client.publish(TopicArn=<SNS ARN goes here>, Message='Hello World')
There are no filter policies active as I want all messages to pass through.
I have 2 questions: Why is the simple publish not getting through?
In order to publish or subscribe I need to know arn values for sns and sqs. The best way I know to obtain them is to call create_(topic/queue) even if the entity already exists. The calls are idempotent so it should be safe but is this the best practice to obtain arn values?