How do I get Boto to return EC2 instances - S3 works fine
Question: I'm having some issues with the EC2 bit of Boto (Boto v2.8.0, Python v2.6.7).

The first command returns a list of S3 Buckets - all good! The second command
to get a list of EC2 instances blows up with a 403 with "Query-string
authentication requires the Signature, Expires and AWSAccessKeyId parameters"

    
    
    s3_conn = S3Connection(AWSAccessKeyId, AWSSecretKey)
    print s3_conn.get_all_buckets()
    
    ec2_conn = EC2Connection(AWSAccessKeyId, AWSSecretKey)
    print ec2_conn.get_all_instances()
    

Also, my credentials are all good (Full admin) - I tested them using the Ruby
aws-sdk, both EC2 and S3 work fine.

I also noticed that the **host** attribute in the ec2_conn object is **s3-eu-
west-1.amazonaws.com** , "s3"...? Surely thats wrong? I've tried retro fixing
it to the correct endpoint but no luck.

Any help would be great appreciate Thanks


Answer: Here's some working code I use to list all my instances across potentially
multiple regions. Its doing a lot more than you need, but maybe you can pare
it down to what you want.

    
    
    #!/usr/bin/python
    import boto
    import boto.ec2
    import sys
    
    class ansi_color:
      red   = '\033[31m'
      green = '\033[32m'
      reset = '\033[0m'
      grey  = '\033[1;30m'
    
    
    def name(i):
      if 'Name' in i.tags:
        n = i.tags['Name']
      else:
        n = '???'
      n = n.ljust(16)[:16]
      if i.state == 'running':
        n = ansi_color.green + n + ansi_color.reset
      else:
        n = ansi_color.red + n + ansi_color.reset
      return n
    
    def pub_dns( i ):
      return i.public_dns_name.rjust(43)
    
    def pri_dns( i ):
      return i.private_dns_name.rjust(43)
    
    def print_instance( i ):
      print '  ' + name(i) + '| ' + pub_dns(i) + ' ' + pri_dns(i)
    
    
    regions = sys.argv[1:]
    if len(regions)==0:
      regions=['us-east-1']
    
    if len(regions)==1 and regions[0]=="all":
      rr = boto.ec2.regions()
    else:
      rr = [ boto.ec2.get_region(x) for x in regions ]
    
    for reg in rr:
      print "========"
      print reg.name
      print "========"
      conn = reg.connect()
    
      reservations = conn.get_all_instances()
    
      for r in reservations:
      #  print ansi_color.grey + str(r) + ansi_color.reset
        for i in r.instances:
          print_instance(i)
    

