1

I'm trying to use my aws credentials file in boto but can't seem to get it to work. I'm new to python and boto so I'm looking at a bunch of stuff online trying to understand this.

All I'm trying to do right now is to just get all ec2 instances...here is my python code:

import boto
from boto import ec2

ec2conn = ec2.connection.EC2Connection(profile_name='profile_name')
ec2conn.get_all_instances()

when I run that, I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py", line 585, in get_all_instances
    max_results=max_results)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/ec2/connection.py", line 681, in get_all_reservations
    [('item', Reservation)], verb='POST')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 1170, in get_list
    response = self.make_request(action, params, path, verb)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 1116, in make_request
    return self._mexe(http_request)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 747, in new_http_connection
    connection = self.proxy_ssl(host, is_secure and 443 or 80)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/connection.py", line 835, in proxy_ssl
    ca_certs=self.ca_certificates_file)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 943, in wrap_socket
    ciphers=ciphers)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 611, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 840, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:661)

I've also tried ec2conn.get_all_reservations() but got the same result...

In boto3, I can do this which works:

import boto3
session = boto3.Session(profile_name='dev')
session = boto3.Session(profile_name='profile_name')
dev_ec2 = session.client('ec2')
dev_ec2.describe_instances()

------EDIT--------

So I found this link on stack...Recommended way to manage credentials with multiple AWS accounts? and what I did was exported my AWS_PROFILE var

export AWS_PROFILE="profile_nm"

that worked when I did this:

>>> import boto
>>> conn = boto.connect_s3()
>>> conn.get_all_buckets()

And I got all of the s3 buckets back...

but when I did the above to get all the ec2 instances back...i still got the ssl.SSLEOFError above. It seems to work with s3 but not ec2 now...So, is the way I get all the Ec2 instances wrong?

Community
  • 1
  • 1
lightweight
  • 3,227
  • 14
  • 79
  • 142
  • 1
    AFAIK boto 2 doesn't use `~/.aws/credentials`, it has its own credentials file. I would recommend using boto3, especially as a new user. – Jordon Phillips Jan 31 '17 at 00:25
  • not sure if I'm reading this right but I think it says in here it does? http://boto.cloudhackers.com/en/latest/boto_config_tut.html – lightweight Jan 31 '17 at 00:43
  • this link helped use the profile name in the aws creds file (http://stackoverflow.com/questions/11286479/recommended-way-to-manage-credentials-with-multiple-aws-accounts/21345540#21345540) and it worked to list all s3 buckets, but I still get the `ssl.SSLEOFError` when I try to get all the ec2 instances... – lightweight Jan 31 '17 at 03:18
  • Apologies, though I prefaced that with afaik I probably should have searched anyway. Can I ask what specific python version you're using? Versions prior to 2.7.9 had some issues with TLS detection. S3 and EC2 have different TLS configurations, which is why one might not work when the other does. – Jordon Phillips Jan 31 '17 at 04:44
  • hey np...maybe I was reading it wrong so just wanted to put in that link...here are my versions for awscli, python, and boto....`aws-cli/1.10.1 Python/2.7.13 Darwin/15.6.0 botocore/1.5.7` – lightweight Jan 31 '17 at 10:43
  • 1
    this ended up being a proxy issue for me...I did `export no_proxy=169.254.169.254` and then it worked – lightweight Jan 31 '17 at 15:22

0 Answers0