Question

My problem is best described by the following script:

import boto
boto.__version__
# OUT: '2.19.0'
from boto.ec2.connection import EC2Connection
ec2 = EC2Connection(**creds)
regions = ec2.get_all_regions()
from boto.sqs.connection import SQSConnection
regions[0]
# OUT: RegionInfo:eu-west-1
sqs = SQSConnection(region=regions[0], **creds)
sqs.get_all_queues()
# OUT: Traceback (most recent call last):
# OUT:   File "<input>", line 1, in <module>
# OUT:   File "/opt/zenoss/lib/python2.7/site-packages/boto/sqs/connection.py", line 338, in get_all_queues
# OUT:     return self.get_list('ListQueues', params, [('QueueUrl', Queue)])
# OUT:   File "/opt/zenoss/lib/python2.7/site-packages/boto/connection.py", line 1119, in get_list
# OUT:     raise self.ResponseError(response.status, response.reason, body)
# OUT: SQSError: SQSError: 400 Bad Request
# OUT: <?xml version="1.0" encoding="UTF-8"?>
# OUT: <Response><Errors><Error><Code>NoSuchVersion</Code><Message>The requested version (2012-11-05) of service AmazonEC2 does not exist</Message></Error></Errors><RequestID>1600907e-6780-46f5-b5e6-e647a660abf8</RequestID></Response>

I could not find documentation for AWS or boto about meaning of this error, and how to fix it. Is that a bug of boto?

Was it helpful?

Solution

The problem with the above code is that the get_all_regions() call from the EC2 module returns a list of RegionInfo objects consisting of a region name and a region endpoint. But the endpoint is for the EC2 service, not SQS. So, if you pass that RegionInfo into the SQSConnection constructor it will end up trying to make SQS requests against an EC2 endpoint which results in the NoSuchVersion error.

Here's how I would do this:

import boto.sqs

sqs = boto.sqs.connect_to_region('eu-west-1')
sqs.get_all_queues()

Similarly, if you need an EC2 connection:

import boto.ec2

ec2 = boto.ec2.connect_to_region('eu-west-1')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top