Search code examples
javaamazon-web-servicesamazon-s3aws-sdk-java-2.0

Delete a folder and its content AWS S3 java


Is it possible to delete a folder(In S3 bucket) and all its content with a single api request using java sdk for aws. For browser console we can delete and folder and its content with a single click and I hope that same behavior should be available using the APIs also.


Solution

  • There is no such thing as folders in S3. There are simply files (objects) with slashes in the filenames (keys).

    The S3 browser console will visualize these slashes as folders, but they're not real.

    You can delete all files with the same prefix, but first you need to look them up with list_objects(), then you can batch delete them.

    For code snippet using Java SDK, please refer to Deleting multiple objects.