Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup AWS SNS and SQS for high availability?

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).

like image 639
Will Avatar asked Sep 08 '16 15:09

Will


People also ask

What is the difference between SNS and SQS in AWS?

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.

How to set up Amazon SQS?

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 ...

What is Amazon Simple Queue Service (SQS)?

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).

What are availability zones in AWS?

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.


1 Answers

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:

  • Writers - Write to one region, if that fails, write to another.
  • Readers - Read from multiple queues across multiple regions.

Another method:

  • Writers - Write to multiple topics/queues, ensures the message gets somewhere.
  • Readers - Read from multiple queues, treat all equally, you will need to manage message duplication.
like image 56
Matt Houser Avatar answered Nov 11 '22 00:11

Matt Houser