Boto3: Get details of all available S3 Bucket details

Viewed 2694

I am trying to list the metadata about all the S3 buckets available in my AWS account using the boto3 client.

I tried below api: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.list_buckets but it just returns the bucket name and created date.

I am looking for more details like:

  1. Bucket Region
  2. Bucket status like Active
  3. Bucket Id (if there is any)

It would be more helpful if I can get a single API which can return all these details as describe_instances of EC2 returns more metadata.

Any help is highly appreciated

1 Answers

Hope, this post of some help!

  1. S3 Region? - I don't think, S3 is region-specific anymore. Also, the bucket name is already a unique value.
  2. As you can see in the same document you have below function for collecting a different kinds of metadata.
get_bucket_accelerate_configuration()
get_bucket_acl()
get_bucket_analytics_configuration()
get_bucket_cors()
get_bucket_encryption()
get_bucket_inventory_configuration()
get_bucket_lifecycle()
get_bucket_lifecycle_configuration()
get_bucket_location()
get_bucket_logging()
get_bucket_metrics_configuration()
get_bucket_notification()
get_bucket_notification_configuration()
get_bucket_policy()
get_bucket_policy_status()
get_bucket_replication()
get_bucket_request_payment()
get_bucket_tagging()
get_bucket_versioning()
get_bucket_website()

These are created just for the reason of segregating information that specifically required for user.

In my opinion, you are looking for get_bucket_inventory_configuration - Returns an inventory configuration (identified by the inventory ID) from the bucket.

This will also return ARN which is a unique id for all AWS resources.

A sample ARN looks like

'Bucket' :"arn:aws:s3:::10012346561237-rawdata-bucket"
Related