2

Meta

Python: 2.7.5
Pip : pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
AWS CLI : aws-cli/1.16.104 Python/2.7.5 Linux/3.10.0-862.3.3.el7.x86_64 botocore/1.12.94
Boto3 : 1.9.94
Centos : CentOS Linux release 7.5.1804 (Core)

My script

import boto3
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
try:
    response = ec2.describe_instances()
    print(response)
except ClientError as e:
    print(e)

When I run my script, I get this exception :

  • botocore.exceptions.SSLError: SSL validation failed for https://ec2.region.amazonaws.com/ hostname 'ec2.region.amazonaws.com' doesn't match either of '*.com.com', 'com.com'

Please any help would be appreciated! Thanks!

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Azhwani
  • 79
  • 1
  • 3
  • 7
  • Did you run $ aws configure to insert your credentials ? – razimbres Feb 14 '19 at 12:40
  • Hello @Rubens_Z, yes I did I already generate the two files : ~/.aws/credentials and ~/.aws/config – Azhwani Feb 14 '19 at 12:57
  • I had this issue with a AWS IoT Core certificate. Probably idle for some time. My solution was to generate another certificate. – razimbres Feb 14 '19 at 13:06
  • What do u mean by generate another certificate? Do I need to install an SSL certificate in my centos server ? – Azhwani Feb 14 '19 at 14:29
  • Probably the certificate I used for AWS IoT Core expired. I am able to run your code in my machine and get the output for EC2, like ImageId, InstanceType, KeyName, etc The only certificate I use is for IoT Core. Did you visit: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html ? – razimbres Feb 14 '19 at 15:51
  • Hello @Rubens_Z, yes i tried to follow all the required steps but what i dont understand is the relation between IoT Core certificate and the python script. I'm trying to run the script in a linux server (centos). I just create a IoT Core certificate, I download the cert files but i dont know what to do with them! Can you point me to the right direction please ? – Azhwani Feb 14 '19 at 16:34
  • There's no relation between IoT Core and boto3 connecting to EC2. I used IoT Core just as an example. – razimbres Feb 14 '19 at 16:48
  • I managed to fix the issue, thank u @Rubens_Z for ur support I really appreciate ur replies! I executed "aws configure" with new infos and everything worked ! Thanks again! – Azhwani Feb 14 '19 at 17:17
  • may I post the solution or do you prefer posting it ? – razimbres Feb 14 '19 at 18:59

2 Answers2

-1

@azhwani, as you are not using AWS IoT Core, this does not seem to be an issue related to an expired certificate.

Run:

$ aws configure

... and insert your AWS credentials.

razimbres
  • 4,715
  • 5
  • 23
  • 50
-2

I have got the solution for this.

Don't install boto3 using pip/pip3.

Use following steps::

$ git clone https://github.com/boto/boto3.git
$ cd boto3
$ virtualenv venv
...
$ . venv/bin/activate
$ pip install -r requirements.txt
$ pip install -e .

It worked for me. Initially I was facing the same SSL Validation Exception problem. Then I uninstalled the boto3 (pip3 uninstall boto3) and re-installed it using virtualenv as stated above. Now, it is working fine.