amazon web services - Running AWS CLI through Python returns a "sh: 1: aws: not found" error -
i trying copy file s3 bucket, using python, so:
cmd = 'aws s3 %s %s' % (filename, bucketname) os.system(cmd) it gives me sh: 1: aws: not found error.
however, using s3cmd works fine.
why s3cmd work, not aws?
also, did which aws , returned: /home/username/anaconda/bin/aws.
which s3cmd returns: /home/username/anaconda/bin/s3cmd.
why 1 work, not other, despite having same root?
a quick way troubleshoot issue try full path on os call see if path problem:
cmd = '/path/to/aws s3 %s %s' % (filename, bucketname) os.system(cmd) there few reasons why problem, related path variable (at first guess). however, might better steer away os.system noted in docs (https://docs.python.org/2/library/os.html#os.system) , use alternative methods.
using subprocess:
cmd = ['/path/to/aws', 's3', filename, bucketname] subprocess.popen(cmd) or use python aws client boto3 package. there many ways, 1 quick example question (how save s3 object file using boto3):
import boto3 s3_client = boto3.client('s3') s3_client.upload_file(filename, bucketname, filename) that 1 not testable moto, can annoying. instead if want test, can this:
import boto3 s3_resource = boto3.resource('s3') open(filename, 'rb') f: binary = f.read() s3_resource.bucket(bucketname).put_object( key=filename, body=binary )
Comments
Post a Comment