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,440 points
333 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,090 points

Related Questions In AWS

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 14 in AWS by Archana
• 5,480 points
14 views
+2 votes
2 answers

Is it possible to ping AWS EC2 instance

Start by adding a new EC2 security group inbound ...READ MORE

answered Apr 9, 2018 in AWS by hemant
• 5,750 points
311 views
0 votes
1 answer

Is it possible to stop nodes in AWS ElastiCache cluster

At this time there is not a ...READ MORE

answered Jun 20, 2018 in AWS by Flying geek
• 3,150 points
138 views
0 votes
1 answer

Is it possible to stop nodes in AWS ElasticCache cluster?

In AWS, ElastiCache clusters cannot be stopped. ...READ MORE

answered Aug 17, 2018 in AWS by Archana
• 4,090 points
46 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,090 points
158 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,090 points
49 views