0

Is there a way to get the list of all regions available on AWS through libcloud ?

With powershell AWS SDK I can use :

$regions = @(Get-AWSRegion)
foreach ($region in $regions)
{
$region.Region
}

How can I do the same with Python and libcloud ?

Many thanks, Johnny

3 Answers3

1

Try this. Crude way of getting the AWS regions:

from libcloud.compute.types import Provider

aws_regions = []
for kw,reg in Provider.__dict__.iteritems():
  if 'EC2' in kw and reg not in aws_regions:
    aws_regions.append(reg)

print aws_regions
helloV
  • 50,176
  • 7
  • 137
  • 145
0

We can make use of libcloud API list_regions()

 (Pdb) import libcloud
 (Pdb) p libcloud.__version__
 '1.5.0'

 (Pdb)  p driver.list_regions()
 ['ap-northeast-2', 'us-east-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-south-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-2', 'us-gov-west-1', 'us-west-1', 'eu-central-1', 'ap-northeast-1']
Viswesn
  • 4,674
  • 2
  • 28
  • 45
0

We can use the get_driver() function on the Provider.EC2 object. The list_regions() method will give you the list of acceptable values to pass when connecting to a region. list_regions

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

driver = get_driver(Provider.EC2)

driver.list_regions()
['ap-northeast-1', 'ap-northeast-2', 'ap-northeast-3', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'cn-north-1', 'cn-northwest-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-gov-west-1', 'us-west-1', 'us-west-2']
JimMcC2
  • 21
  • 2