With the GetStatistics API you can search an index for aggregate data.
Here are some examples how to get statistics about your fleet:
Get number of devices connected to AWS IoT
aws iot get-statistics --query-string "connectivity.connected:true"
Number of devices in building Day One
aws iot get-statistics --query-string "attributes.building:Day_One"