![the bucket list script the bucket list script](http://3.bp.blogspot.com/-HueG2niHT80/UBxxSCIs-iI/AAAAAAAAGQ0/00nNhCr9OLI/s640/pinkShip.jpg)
We have used list_objects_v2 in this for loop to get count of objects present in S3 bucket here print("Before deleting the bucket we need to check if its empty. Note:- If any object is present in S3 bucket it wont be deleted. We will use for loop now use for loop to first check if there is any object existing in this S3 bucket.bucket_name=str(input('Please input bucket name to be deleted: ')) Now we will use input() to take bucket name to be deleted as user input and will store in variable " bucket_name".
#The bucket list script code
To view entire github code please click here Delete S3 Bucket If No Objects Exists
![the bucket list script the bucket list script](https://www.irishtimes.com/polopoly_fs/1.2522781.1454603593!/image/image.jpg)
Tag_value = str(input("Please enter value for the tag: ")) Tag_key=str(input("Please enter key for the tag: ")) In method parameters we are passing variable as " bucket_name"," tag_key"," tag_value". To add tag to bucket we are going to use put_bucket_tagging() method, make sure to check official documentation here We will store tag key in variable " tag_key" and tag value in " tag_value".
#The bucket list script install
Install awscli using aws official documentation here.Always adhere to the principle of least privilege when authorizing accounts to perform actions. IAM policy creation and AWS Application Programming Interface (API) permissions are outside this article’s scope. The IAM permissions required to perform IAM, S3, and CloudWatch activities.AWS Management Console access to verify your S3 buckets launched,listed and deleted.In this blog we are going to create python script to list, create and delete S3 buckets using boto3.