title: Using aws profiles in python2 boto
body: <p>I'd like my python script (connecting to aws) to use aws profiles from ~/.aws/credentials</p>
  
  <p>So, I have ~/.aws/credentials file:</p>
  
  <pre><code>[default]
  aws_access_key_id = XXX
  aws_secret_access_key = AAA
  region = eu-west-1
  
  [test]
  aws_access_key_id = WWW
  aws_secret_access_key = ZZZ
  region = eu-west-1
  </code></pre>
  
  <p>My python code</p>
  
  <pre><code>import boto.ec2
  
  conn = boto.ec2.EC2Connection(profile_name='test')
  print conn
  print conn.get_all_instances()
  </code></pre>
  
  <p>The output is</p>
  
  <pre><code>EC2Connection:ec2.us-east-1.amazonaws.com
  []
  </code></pre>
  
  <p>So, it doesn't seem to take the profile from the config. The region is wrong.</p>
  
  <pre><code>env | grep -i aws &lt;- returns nothing
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Thank you.</p>
  
  <p>===== UPDATE =====</p>
  
  <p>I have a ~/.aws/config file too which looks like</p>
  
  <pre><code>⟩ cat config
  [default]
  output = text
  region = eu-west-1
  
  [profile test]
  output = text
  region = eu-west-1
  </code></pre>
  
  <p>===== UPDATE =====</p>
  
  <p>apparently, it takes connection details.. but not region. So, if I do</p>
  
  <pre><code>reg = next(x for x in boto.ec2.regions() if x.name=='eu-west-1')
  
  conn = boto.ec2.EC2Connection(profile_name='test', region=reg)
  print conn
  print conn.get_all_instances()
  </code></pre>
  
  <p>I can get a list of the instances.</p>
  
  <p>So, the problem is how to get the default 'region' from AWS config/credentials.</p>