How to delete a complete directory from an S3 bucket

I need to remove a whole S3 directory from a bucket that has a specific prefix, such as /abc_directory. The directory contains over 100 files. I plan to use the javascript aws-sdk to connect to S3 and accomplish this task.

You can use JS but you should call a query that runs a Delete using an s3 resource:
Screenshot 2023-08-23 at 8.42.38 AM

1 Like

Hi @ScottR Thank you for your response. However, I would like to clarify that the method you suggested will only allow me to delete one file at a time. What I actually want to do is delete the entire directory.

Hi @Dirshant_Kumar,

With the method that Scott suggests, you can use our native S3 integration and a Js loop (docs here) to delete each file one by one. This is the solution I'd suggest as well

I'm not too familiar with the sdk, but if there is a bulk delete method, that can be referenced in a Javascript query, that may be easier! I'll move this to our Discussion category, in case there are other community members using the sdk that can chime in

@Tess I attempted this with SDK, but it requires adding * to GET requests in the Production S3 CORS policy, which poses a security risk. and Also dropped post for that as well please check here (community post)

Hi @Dirshant_Kumar Circling back here! Was Joe's comment in the linked post helpful? Just to clarify, did you mean that you attempted this with the JS SDK or our s3 integration?