Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Services >> Cloud >> AWS >> SDK >> Python >> boto3 >> How to manage s3 service

 

 

List buckets and objects in them

#!/usr/bin/python3
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
   print('[-]',bucket.name)
   for item in bucket.objects.all():
       print(" |")
       print(' +--',item.key)

 

 

Delete all object versions in versioned bucket

 

#!/usr/bin/env python 
BUCKET = 'your-bucket-here' 
import boto3 
s3 = boto3.resource('s3')
bucket = s3.Bucket(BUCKET)
bucket.object_versions.delete() 

# if you want to delete the now-empty bucket as well, uncomment this line:
#bucket.delete()

 

 

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]