简体   繁体   中英

getting PermissionError: [Errno 13] Permission denied while uploading to s3

when I try to upload file to my ASW s3 using python and boto3 it is working fine and i am successfully able to upload it to aws s3 but when i try to upload a folder i am getting

getting PermissionError: [Errno 13]

my code is

def upload_to_aws(local_file, bucket, s3_file):
    s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
                      aws_secret_access_key=SECRET_KEY)

    try:
        s3.upload_file(local_file, bucket, s3_file)
        print("Upload Successful")
        return True
    except FileNotFoundError:
        print("The file was not found")
        return False
    except NoCredentialsError:
        print("Credentials not available")
        return False 

upload_file is only for uploading files, not folders. You have to iterate over all the files in your folder, and for each, execute upload_file operation.

@Marcin is right.

Its also crucial to understand the structure of s3 buckets. Because s3 is an object storage, it actually has no folder structure. The folders you create in your buckets are just objects that are visually grouped by the file name like /**folder**/myfile.pdf . This is done so we can interact with the objects easier. But S3 is not a file storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM