QT-DevOps / AWSIssues

Issues with AWS
Apache License 2.0
3 stars 26 forks source link

Unable to Delete specific objects on S3 bucket(versioning enabled) #105

Closed Ashokecm closed 4 years ago

Ashokecm commented 4 years ago

I have tried the following scripts but no luck. 1) This script will list the objects that match the criteria we specify and then delete them.


!/bin/bash

for day in {20191110..20191130} do aws s3api list-object-versions --bucket my-bucket --prefix $day --output json --query 'Versions[*].[Key,VersionId]' | jq -r '.[] | "--key '\''" + .[0] + "'\'' --version-id " + .[1]' | xargs -L1 echo aws s3api delete-object --bucket my-bucket done

2) This script will list the objects that match the criteria we specify and tags the objects, then we need to apply the lifecycle policy to expire the objects.


!/bin/bash

for day in {20191110..20191030} do aws s3api list-object-versions --bucket my-bucket --prefix $day --output json --query 'Versions[*].[Key,VersionId]' | jq -r '.[] | "--key '\''" + .[0] + "'\'' --version-id " + .[1]' | xargs -L1 echo aws s3api put-object-tagging --bucket my-bucket --tagging \'{\"TagSet\": [{ \"Key\": \"action\", \"Value\": \"delete\" }]}\' done


please provide any suggestions

Regards, Ashok