Using PowerShell and AWS CLI to Get Object Count


Yesterday I had to find the count of objects in a folder in an S3 bucket. I only had access to AWS via command line and was working on a Windows Server.

After a bit digging around I found the solution using PowerShells’ Measure-Object cmdlet.

The solution to get the object count was:

aws s3 ls s3://{bucket}/path/to/files | Measure-Object

This can also be used in local folders as well. It also can be used to get the minimum / maximum / average / total size of the folder too so quite handy to get some quick stats about a folder/bucket

While trying it out again I had to install AWS CLI on my Mac. So just for future reference to be able to use AWS CLI on macOS you can install it with Brew as following:

brew install awscli