Home > Net >  Is it Possible to Delete AWS S3 Objects Based on Object Size
Is it Possible to Delete AWS S3 Objects Based on Object Size

Time:11-20

I don't seem to find any document about deleting S3 objects based on the object size. For example if an object size is less that 5B then delete it.

CodePudding user response:

Yes, it is possible to delete an S3 Object based on size.

One workaround is to get the Object size of the S3 bucket via AWS CLI ( you can use cli or boto3 ) and performing a cron job that will perform the condition when true if the object size is less than 5B.

CodePudding user response:

The DeleteObject() API call does not accept parameters such as Size or ModifiedDate.

Instead, you must provide a list of object(s) to be deleted.

If you wish to delete objects based on their size, the typical pattern would be:

  • Call ListObjets() to obtain a listing of objects in the bucket (and optionally in a given prefix)
  • In your code, loop through the returned information and example the object size. Where the size is smaller/larger than desired, add the Key (filename) to an array
  • Call DeteleObject(), passing the array of Keys to be deleted
  • Related