Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Mar 30, 2020

Searching Amazon S3 files using the aws cli

I recently had a need to search Amazon S3 files and was very excited to discover how powerful the aws cli tool was when combined with the jmes query language

The first step was to install the aws cli tool. There is a graphic installer available for macOS, but I installed via the command line:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /

I checked to make sure it had worked, and then removed the installer:

aws --version
rm AWSCLIV2.pkg

The second step was configuration – just a matter of issuing a command and then providing response to configuration questions (key, secret, region, etc).

aws configure

Once that was done, it was very easy to query files. Here are a few basic examples:

Search S3 files by owner

aws s3api list-objects --bucket your-bucket --query "Contents[?Owner.DisplayName == 'someone']"

Search S3 files not by owner

aws s3api list-objects --bucket your-bucket --query "Contents[?Owner.DisplayName != 'someoneelse']"

Search S3 files by key

aws s3api list-objects --bucket your-bucket --query "Contents[?contains(Key, 'path/to/your/file')]"

Search S3 files by date

aws s3api list-objects --bucket your-bucket --query "Contents[?LastModified > '2020-03-26']"

Keep in mind that, as far as I know, the searching is happening on your end, so the requests can be a bit slow, but still a heck of lot faster and more effective than manually combing through files in Transmit which is what I wondered if I might have to do before checking to see what other options were available!

The cli has options that allow for various ouput formats, coloured output, and so on.

Happy searching!

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus