1

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

luk2302
  • 50,400
  • 22
  • 92
  • 131
x89
  • 1
  • 3
  • 21
  • 50
  • Does this answer your question? [Difference in boto3 between resource, client, and session?](https://stackoverflow.com/questions/42809096/difference-in-boto3-between-resource-client-and-session) – luk2302 Oct 20 '21 at 08:34

1 Answers1

3

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(...)
luk2302
  • 50,400
  • 22
  • 92
  • 131
  • What about the open function? ```(s3.open(s3_file_path, mode="wb"))``` It gives me an error with both S3 (client) and s3_resource (resource) – x89 Oct 20 '21 at 08:39
  • @x89 there is no such thing as `s3.open` in boto. Are you sure you want to `open` an s3 object and not a local file? – luk2302 Oct 20 '21 at 08:41
  • Ah yes, you're right - Could you take a look here? https://stackoverflow.com/questions/69641719/use-boto-for-gzipping-files-instead-of-sfs3 – x89 Oct 20 '21 at 08:48