Reputation: 191
I'm new to Boto3 and AWS API, and I want to get the list of buckets' names and the count of the available buckets in S3.
Any help is appreciated.
Upvotes: 4
Views: 4727
Reputation: 52375
To get all buckets in your account:
import boto3
s3 = boto3.resource('s3')
bucket_list = [bucket.name for bucket in s3.buckets.all()]
print len(bucket_list)
print bucket_list
Upvotes: 6
Reputation: 1390
This script will help you to list all the bucket names and also get the count.
import boto
from boto.s3.connection import OrdinaryCallingFormat
conn = boto.connect_s3(calling_format=OrdinaryCallingFormat())
count = 0
print ("Bucket names: ")
for bucket in conn.get_all_buckets():
print (bucket.name)
count = count + 1
print ("Total count of S3 bucket is ", count)
Note : please specify aws keys in script if you are not yet specified it in .boto file
Hope it helps !!
Upvotes: 0