Is it possible to find all S3 buckets given a prefix

0 votes

l have multiple buckets with an application prefix and a region suffix e.g. Bucket names

  • myapp-us-east-1

  • myapp-us-west-1

Is there a way of finding all buckets given a certain prefix? Is there something like:

s3 = boto3.resource('s3') buckets = s3.buckets.filter(Prefix="myapp-")

Aug 27, 2018 in AWS by datageek
• 2,540 points
6,628 views

1 answer to this question.

0 votes

The high level collection command s3.buckets.filter only work for ways that document under describe_tags Filters. In such case, you MUST tag your bucket (s3.BucketTagging) before you can use the very specific filtering method s3.buckets.filter(Filters=formatted_tag_filter)

Currently, you can do this

s3 = boto3.resource('s3')
for bucket in s3.buckets.all(): 
  if bucket.name.startswith("myapp-")" 
     print bucket.name
And following is example code given to filter out KEYS 
# S3 list all keys with the prefix '/photos'
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
    if bucket.name.startswith("myapp-")" :
        for obj in bucket.objects.filter(Prefix='/photos'):
            print('{0}:{1}'.format(bucket.name, obj.key))
Try this out
answered Aug 27, 2018 by Archana
• 4,170 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

Is it possible to add a compatibility layer above AWS?

Well there are few tools like TyphoonAE ...READ MORE

answered Jan 15, 2019 in AWS by Archana
• 5,640 points
588 views
0 votes
1 answer
+2 votes
1 answer

If s3 is global then why we need to select a region while launching it?

This might help you with your query.  Have ...READ MORE

answered Feb 18, 2020 in AWS by Sirajul
• 59,230 points
1,680 views
0 votes
1 answer

POST request to S3 is returning a HTTPResponse 405

This error has nothing to do with ...READ MORE

answered Aug 13, 2018 in AWS by Archana
• 4,170 points
5,326 views
0 votes
1 answer

How to upload a file to Amazon S3 without passing it my server?

This article pretty much explains the entire ...READ MORE

answered Aug 14, 2018 in AWS by Archana
• 4,170 points
3,267 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP