How can k use the AWS SDK or AWS CLI’s “list buckets”?
I am currently working on a particular task which is related to managing of AWS S3 bucket. I need to audit and list all the buckets so that I can ensure compliance with the policies of the company. How can I programmatically accomplish this particular task by using the AWS SDK or AWS CLI’s “list buckets” functionalities?
In the context of AWS, you can programmatically list all the AWS S3 buckets by using the AWS SDK or AWS CLI’s “list buckets” functionalities:-
AWS SDK (python/Boto3)
# AWS SDK (Python/Boto3)
Import boto3
# Create an S3 client
S3_client = boto3.client(‘s3’)
# List all buckets
Response = s3_client.list_buckets()
# Print bucket names
For bucket in response[‘Buckets’]:
Print(bucket[‘Name’])
AWS command line interface
By using the command line interface of AWS, you can simply implement the following command in your particular terminal:-
“aws S3 ls”