24

I'm receiving this error 'S3' object has no attribute 'Bucket' any idea? below is my code

self.client = boto3.client(
        's3',
        aws_access_key_id= access_key,
        aws_secret_access_key= secret
    )
the_bucket = self.client.Bucket('my_bucket') # but I'm receiving an error here
MadzQuestioning
  • 3,341
  • 8
  • 45
  • 76
  • Possible duplicate of [Difference between resource,client and session..?](https://stackoverflow.com/questions/42809096/difference-between-resource-client-and-session) – mootmoot Nov 24 '17 at 17:56
  • 2
    You are confusing between boto3.s3.client vs boto3.s3.resource. There is no such class for s3.client.Bucket , only s3.resource.Bucket is valid. – mootmoot Nov 24 '17 at 18:00

1 Answers1

61

There is more than one way to interact with Boto3.

The high-level one using resource() and classes like S3.Bucket. And the low-level one using boto3.client(...). You are kind of mixing these two.

If you look here it will clarify the difference. In short...

High-level example

s3 = boto3.resource('s3') 
the_bucket = s3.Bucket('my_bucket')

Low-level example

self.client = boto3.client(...)
self.client.create_bucket(...)
Grzegorz Oledzki
  • 23,614
  • 16
  • 68
  • 106
  • 9
    Why distinguish the two? is there a benefit for using one over the other? – chaikov Oct 25 '19 at 02:30
  • 3
    The documentation for boto3 is really confusing, the same thing happened to me to try to remove a file, I ended up mixing the methods. Here is the complete list of methods available for using the client mode: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html?highlight=delete_object#client – Fernando Tholl Feb 17 '21 at 23:23