I want to find out if it is possible to check via boto3 if a EBS volume which is attached to an EC2 instance is mounted. The reason for this is that I believe a number of instances have had volumes unmounted, but the admin has forgotten to detach the volume, so the volumes is billed, but we're not using it.
I can't see anything in the boto3 documentation, the only thing I can think of is to try and detach the volume and see if it errors, which would worry me as a method in case the volume is detached from the instance when it is mounted and in use, it could cause serious issues.
The only other thing I can think of is to use salt-key (which we use to manage config) to print out a list of instances, then run a "df -h" on the server, stripping out the LVMs, and return the list of volumes that are mounted, which I could cross reference with the list of volumes that the instance has attached from boto3. This seems like a safer way to do it, but could be a pain, and could only be run on our salt master.
lsblk
might be more straightforward/easier to use thandf
. – Michael - sqlbot