x89
x89

Reputation: 3460

S3 object has no attribute Bucket

I am trying to run a code snippet like this:

s3_file_path = "testunzipping/sample.csv.gz"
s3 = boto3.client('s3')
lst = s3.list_objects(Bucket='testunzipping')['Contents']
firstbucket = s3.Bucket('testunzipping')

but I am getting an error on the last line that:

"errorMessage": "'S3' object has no attribute 'Bucket'",

Later I am using the first bucket like this:

firstbucket.upload_fileobj(destination_file_gz, s3_filename)

What am I doing wrong? I also tried with bucket instead of Bucket

Upvotes: 1

Views: 6467

Answers (1)

luk2302
luk2302

Reputation: 57114

There is a difference between boto.client and boto.resource

.Bucket is only defined on the latter:

s3_resource = boto3.resource('s3')
bucket = s3.Bucket('name')

vs.

s3_client = boto3.client('s3')
s3.list_objects(...)

Upvotes: 3

Related Questions