l3_08 l3_08 - 2 months ago 5x
Python Question

Get the names and count of all buckets in AWS S3

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.


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