Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman request : ImportError: cannot import name DEFAULT_CIPHERS

I'm using a Red Hat EC2 instance in order to run AWS CLI commands and manage some tasks with Glacier and S3. I'm also designing a Rest API in order to execute the scripts I've deployed on the EC2. Using Postman to send a POST request to the EC2's public DNS address, my script will take in a raw JSON and decode it for parameters my PHP script will take in. I run into an error when I try to execute the AWS CLI commands within my PHP script. The AWS commands work when I run them in the terminal.

Things I have tried from this thread

https://github.com/aws/aws-cli/issues/3542:

  • pip install AWScli instead of pip install AWS
  • downgrading AWSversions and Botocore

Postman Response

Traceback (most recent call last):
  File "/usr/bin/aws", line 19, in <module>
    import awscli.clidriver
  File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 17, in <module>
    import botocore.session
  File "/usr/lib/python2.7/site-packages/botocore/session.py", line 30, in <module>
    import botocore.credentials
  File "/usr/lib/python2.7/site-packages/botocore/credentials.py", line 42, in <module>
    from botocore.utils import InstanceMetadataFetcher, parse_key_val_file
  File "/usr/lib/python2.7/site-packages/botocore/utils.py", line 31, in <module>
    import botocore.httpsession
  File "/usr/lib/python2.7/site-packages/botocore/httpsession.py", line 7, in <module>
    from urllib3.util.ssl_ import (
ImportError: cannot import name DEFAULT_CIPHERS

Php Script

exec("aws s3 cp s3://$BucketName /path/to/dir/ --recursive 2>&1",$output,$return);

I expected the AWS CLI commands to be executed by the exec command and return a string output, which I would send back as a response.

like image 433
Edwin Avatar asked Apr 20 '19 02:04

Edwin


2 Answers

Fixed this problem by running this command

sudo pip install awscli --force-reinstall --upgrade

like image 149
Edwin Avatar answered Sep 23 '22 13:09

Edwin


For me, this fixed the problem:

sudo pip install boto3 --force-reinstall --upgrade

just in case, try this step later:

sudo pip install awscli --force-reinstall --upgrade
like image 26
user183460 Avatar answered Sep 24 '22 13:09

user183460