One of my clients uses a 1.5TB sized bucket on Amazon S3 and regularly needs to have a file removed because of copyright claims or something like that. It’s mostly a legacy bucket without any proper file structure. You can imagine searching through all of the folders is something of a nightmare. At least manually. Enter S3 CLI.
Amazon provides for a command line interface that allows you to do various things inside an S3 bucket. Searching for specific files is one of them. Let me share how.
AWS Buckets CLI
Time needed: 2 minutes.
There are just a few small steps. Easy peasy if you’re somewhat familiar with the Command Line interface of your machine.
- Install AWS CLI
You’ll want to follow AWS’ installation guide for the CLI first. Once you have everything up and running on your local machine, move to step 2.
- Connect your AWS account with AWS CLI
Follow these steps to make sure your local machine actually knows to which bucket under which AWS account it needs to talk.
- Open up your terminal
Now for the fun part; finding where that file is located. We’re using
nameofbucket.example.com/for the name of the bucket and we’re looking for the following file:
To do that, enter this command into your terminal:
aws s3 ls s3://nameofbucket.example.com/ --recursive | grep aristotle-was-right.jpg
- Delete your file
This results in the exact location of the requested file, if it indeed exists. Delete how you see fit. Either by manually navigating to the given folder structure or via the command line you find yourself using. The sky is the limit
Hope this saves you some searching and figuring out.