Problem with SNS
I'm currently using the python boto3 library for SNS (e.g. to create topics, subscribe to topics, send SNS to topics). When I use either a Resource or a Client, I have to specify a region (e.g. 'us-west-2', 'us-east-1'). I don't see any built-in options for handling region failover. My question is, how do you setup AWS SNS and SQS for high availability/region failover?
import boto3
client = boto3.client('sns', region_name='us-west-2')
response = client.create_topic(Name='my_new_topic')
client.subscribe(TopicArn='arn:aws:sns:us-west-2:123456789:some-topic', Protocol='HTTP', Endpoint='Some-HTTP-Endpoint')
Thoughts on Solution for SNS
I was thinking of checking the response of the client. For example, the below is the response of a successful client.create_topic()
.
{'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'adbb58ef-9047-5d44-834d-04a41599eb2b'}, u'TopicArn': 'arn:aws:sns:us-west-2:123456789:some-topic'}
If the request didn't succeed, I can retry say X times before attempting a new region_name
, but this method seems really hacky (since it would always attempt to try the region that's down first and need to keep switching to new clients).
Problem with SQS
If the above were to succeed (where we can handle SNS across regions), now I have multiple SQS Queues that I would need to read from (again with what seems to be a hacky solution of looping through clients with different regions).