Python Boto Ignore AWS Region

Python Boto Ignore AWS Region

By default the Python Boto has all the regions for Amazon Web Services (AWS) to it. This may also include the regions which you don’t have access to.

This does not affect much unless you tend to use the prebuilt functions for Boto, which provides you the list of regions.

Let’s take a look at this function and the output it provides.

Python Boto Ignore AWS Region

We will list the available regions for EC2 in our existing Boto module.

>>> import boto.ec2
>>> for region in boto.ec2.regions():
...   print(region)
... 
RegionInfo:us-east-1
RegionInfo:cn-north-1
RegionInfo:ap-northeast-1
RegionInfo:eu-west-1
RegionInfo:ap-southeast-1
RegionInfo:ap-southeast-2
RegionInfo:us-west-2
RegionInfo:us-gov-west-1
RegionInfo:us-west-1
RegionInfo:sa-east-1

As you can see in the above example these are the default regions available for EC2 in Boto.

However, there are certain regions which aren’t accessible to all. For instance us-gov-west-1 & cn-north-1.

These can generate errors while you are trying to script something which uses the boto.XXX.regions() function. You can write the ignore cases around the script to ignore certain regions for AWS, but it can be cleaner if you can remove those regions from Boto itself.

Python Boto Ignore AWS Region

You can ignore or remove AWS region from Boto by modifying the file endpoints.json. You can find this file inside of the boto module folder under the modules path for your Python installation.

On Fedora/RedHat/CentOS, the path for Python modules folder is /usr/lib/pythonx.x/site-packages.

In my case the file was located under /usr/lib/python2.6/site-packages/boto/.

You simply need to modify the file endpoints.json, and remove the regions which you do not want to be included from the various services listed for Amazon Web Services (AWS).

[[email protected] ~]# vim /usr/lib/python2.6/site-packages/boto/endpoints.json

That should do it. In my case I removed us-gov-west-1 & cn-north-1.

Verify and confirm that the regions are no longer listed in the boto.XXX.regions() function.

>>> import boto.ec2
>>> for region in boto.ec2.regions():
...   print(region)
... 
RegionInfo:us-east-1
RegionInfo:ap-northeast-1
RegionInfo:eu-west-1
RegionInfo:ap-southeast-1
RegionInfo:ap-southeast-2
RegionInfo:us-west-2
RegionInfo:us-west-1
RegionInfo:sa-east-1

Python Boto Ignore AWS Region

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.