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')
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).
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).
Comparisons: SQS vs SNS in AWS — Simple Notification Service and Simple Queue Service. SNS is a distributed publish-subscribe service. SQS is distributed queuing service. Amazon SNS is a fast, flexible, fully managed push notification service that lets you send individual messages or to bulk messages to large numbers of recipients.
Setting up Amazon SQS Step 1: Create an AWS account. To access any AWS service, you first need to create an AWS account, an Amazon.com account... Step 2: Create an IAM user. Sign in to the IAM console as the account owner by choosing Root user and entering your AWS... Step 3: Get your access key ID ...
The Amazon Simple Queue Service (SQS) and the Amazon Simple Notification Service (SNS) are important “glue” components for scalable, cloud-based applications (see the Reference Architectures in the AWS Architecture Center to learn more about how to put them to use in your own applications).
Availability Zones are more highly available, fault tolerant, and scalable than traditional single or multiple data center infrastructures. For more information about AWS Regions and Availability Zones, see AWS Global Infrastructure. In addition to the AWS global infrastructure, Amazon SQS offers distributed queues.
Amazon SNS and SQS are regional services. There is no built-in multi-region availability method for them. If a region fails and you cannot access your topic or queue, you cannot access those same topics/queues by using another region.
There also isn't any standard way to handle them in a multi-region fashion. It really depends on the workings of your application.
One method:
Another method:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With