dnul
dnul

Reputation: 717

boto.sqs connect to non-aws endpoint

I'm currently in need of connecting to a fake_sqs server for dev purposes but I can't find an easy way to specify endpoint to the boto.sqs connection. Currently in java and node.js there are ways to specify the queue endpoint and by passing something like 'localhst:someport' I can connect to my own sqs-like instance. I've tried the following with boto:

fake_region = regioninfo.SQSRegionInfo(name=name, endpoint=endpoint)
conn = fake_region.connect(aws_access_key_id="TEST", aws_secret_access_key="TEST", port=9324, is_secure=False);

and then:

queue = connAmazon.get_queue('some_queue')

but it fails to retrieve the queue object,it returns None. Has anyone achieved to connect to an own sqs instance ?

Upvotes: 3

Views: 1153

Answers (1)

pfhayes
pfhayes

Reputation: 3927

Here's how to create an SQS connection that connects to fake_sqs:

region = boto.sqs.regioninfo.SQSRegionInfo(
  connection=None,
  name='fake_sqs',
  endpoint='localhost',  # or wherever fake_sqs is running
  connection_cls=boto.sqs.connection.SQSConnection,
)

conn = boto.sqs.connection.SQSConnection(
  aws_access_key_id='fake_key',
  aws_secret_access_key='fake_secret',
  is_secure=False,
  port=4568,  # or wherever fake_sqs is running
  region=region,
)

region.connection = conn

# you can now work with conn
# conn.create_queue('test_queue')

Be aware that, at the time of this writing, the fake_sqs library does not respond correctly to GET requests, which is how boto makes many of its requests. You can install a fork that has patched this functionality here: https://github.com/adammck/fake_sqs

Upvotes: 3

Related Questions