2 Answers
- Newest
- Most votes
- Most comments
0
Did you try adding "/" at the end and see how it works.
Here is how I use to delete the delete markers:
import boto3
bucket = 'bkt_name'
my_session = boto3.Session(profile_name='cli_profile_name')
s3_client = dev_session.client('s3')
#s3_client = boto3.client('s3')
object_response_paginator = s3_client.get_paginator('list_object_versions')
delete_marker_list = []
for object_response_itr in object_response_paginator.paginate(Bucket=bucket , Prefix ="prefix_name/",PaginationConfig={
'MaxItems': 22000,
'PageSize': 100
}):
if 'DeleteMarkers' in object_response_itr:
for delete_marker in object_response_itr['DeleteMarkers']:
if(len(delete_marker['Key'].split('/')[len(delete_marker['Key'].split('/')) -1 ] ) > 0 ):
output = dev_s3_client.delete_objects(Bucket=bucket,Delete={'Objects': [{'Key': delete_marker['Key'], 'VersionId': delete_marker['VersionId']}] , 'Quiet': True })
print(output)
Replace bkt_name, cli_profile_name and prefix_name in the above script. Test it first in your lower test environment and verify if this is working as expected for you and then only do it in your actual environment.
Hope you find this useful.
Comment here if you have additional questions, happy to help.
Abhishek
0
I have tried adding / at the end and it doesn't change the results. I'd like to accomplish this with Powershell instead of Python if possible.
answered a year ago
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 4 years ago
Would you mind pasting your snippet here, I can definitely help.