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

Time:12-24

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 

CodePudding user response:

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.

CodePudding user response:

@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.

  • Related