In this post we are going to see an aws cli command to list elastic file systems sorted by Size in ascending or descending order.
While am sharing all the new tricks in AWS CLI I come across. this is something I have learnt recently
There is a dedicated post of AWS CLI EC2 examples. you might want to take a look may be later.
With no further ado, lets go the objective.
AWS CLI List EFS - Sort by Size Descending
we are going to use aws efs describe-file-systems
command here with query
to select only the necassary elements of the entire output.
with in the query
we are using the sort_by
function to sort the SizeInBytes
field, By Default it would be sorted in Ascending order.
sort_by(@, &SizeinBytes)
As we want to sort in descending order, we need to use reverse
the sort_by function like this
reverse(sort_by(@, &SizeinBytes))
As AWS CLI uses JMESPath for the querying. you can read more about JMESPath Sort_by function to understand how it works.
Here is the complete AWS CLI command to list file systems sorted by size in descending order.
~|⇒ aws efs describe-file-systems – query "FileSystems[*].{FileSystemID:FileSystemId, Name:Name, SizeinBytes: SizeInBytes.Value}| []|reverse(sort_by(@, &SizeinBytes))" – profile prod – output table ------------------------------------------------------------ | DescribeFileSystems | +--------------+------------------------+------------------+ | FileSystemID | Name | SizeinBytes | +--------------+------------------------+------------------+ | fs-4b0****0 | efs-drive1 | 44920832974848 | | fs-c39****6 | attachment-efs | 419247616000 | | fs-4f2****b | remotedrive | 215773437952 | | fs-23f****6 | backupfiles | 57853181952 | | fs-ad0****e | sharedblog | 15373717504 | | fs-76b****5 | None | 330199040 | | fs-46e****7 | eks-sharedrive | 322668544 | | fs-fc0****8 | attachement-new | 53434368 | | fs-188****c | backend-backup | 12474368 | | fs-e33****7 | archiving | 4063232 | +--------------+------------------------+------------------+
AWS CLI List EFS - Sort by Size Ascending
Like the previous descending
command we are going to use the same command with a slight modification
We are just going to remove the reverse
in front of the sort_by
function and let it function by default.
sort_by(@, &SizeinBytes)
Here is the complete AWS CLI command and the execution output.
~|⇒ aws efs describe-file-systems – query "FileSystems[*].{FileSystemID:FileSystemId, Name:Name, SizeinBytes: SizeInBytes.Value}| []|sort_by(@, &SizeinBytes)" – profile prod – output table ------------------------------------------------------------ | DescribeFileSystems | +--------------+------------------------+------------------+ | FileSystemID | Name | SizeinBytes | +--------------+------------------------+------------------+ | fs-e33****7 | archiving | 4063232 | | fs-1886***c | backend-backup | 12474368 | | fs-fc0****8 | attachement-new | 53434368 | | fs-46e****7 | eks-sharedrive | 322668544 | | fs-76****d5 | None | 330199040 | | fs-ad0****e | sharedblog | 15373717504 | | fs-23f****6 | backupfiles | 57853181952 | | fs-4f2****b | remotedrive | 215773437952 | | fs-c39****6 | attachment-efs | 419247616000 | | fs-4b0****0 | efs-drive1 | 44920832974848 | +--------------+------------------------+------------------+
Hope this short article helped you and you can implement this Sort descending or ascending with sort_by
and reverse(sort_by)
function in any other EC2 CLI commands while querying.
This can be a good example of aws efs describe-file-systems
command with sorting.
If you have any best practices and EC2 CLI commands please let us know in the commands for us and others to learn from you.
Cheers
Sarav AK
Follow me on Linkedin My Profile Follow DevopsJunction onFacebook orTwitter For more practical videos and tutorials. Subscribe to our channel
Signup for Exclusive "Subscriber-only" Content