i am new to aws, when ever i am trying to download a file it is giving this error
I am using boto3
AttributeError: 'S3' object has no attribute 'Bucket'
below is my code snippet
try:
s3.Bucket(bucketname).download_file(key,directory)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print("The object does not exist.")
How are you creating the s3 object?
Because s3 = boto3.client('s3') does not have Bucket and s3 = boto3.resource('s3') does have bucket.
I agree with @chenhe95 's suspicion. If you use the client interface to access the bucket:
boto3.client('s3').Bucket('mybucket')
you will get that error. Instead you need to be doing something like this:
boto3.resource('s3').Bucket('mybucket')
Let us know if that helps.
Closing due to inactivity
Most helpful comment
How are you creating the s3 object?
Because
s3 = boto3.client('s3')does not have Bucket ands3 = boto3.resource('s3')does have bucket.