Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing nested buckets in S3 with Boto3

I know the path of the bucket I want to access /bucket1/bucket2/etc/ but I can't figure out how to access it via boto3.

I can enumerate all buckets starting from the source, but can't get to the bucket I want.

For example I can do:

prod_bucket = s3.Bucket('prod')

But I cannot do:

prod_bucket = s3.Bucket('prod/prod2/')

TIA

like image 536
mr-sk Avatar asked Dec 11 '25 17:12

mr-sk


1 Answers

There are no nested buckets. You have bucket and objects.

s3 = boto3.client('s3')
object = s3.get_object(Bucket='prod', Key='prod2/..')

Or:

s3 = boto3.resource('s3')
bucket = s3.Bucket('prod')
object = bucket.Object('prod2/..')

See: get_object

like image 66
helloV Avatar answered Dec 13 '25 05:12

helloV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!