I am running an AWS query
command for aws fsx describe-file-systems
where I want to combine two operators where it will be looking for FileSystemType=="LUSTRE"
and another where Storagecapacity >1200
and then following the another stuff with the query.
In order to get the results I tried below command which came with an error:
aws fsx describe-file-systems --query "FileSystems[?FileSystemType=='LUSTRE' && Storagecapacity >1200 ] | reverse(sort_by(@, &LustreConfiguration.PerUnitStorageThroughput))[].{Name:Tags[?Key=='Name']|[0].Value, Storagecapacity:StorageCapacity, FS_ID:FileSystemId,Type:FileSystemType, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}" --profile demo --output table --no-cli-pager
Error produced by the above command:
Bad value for --query FileSystems[?FileSystemType=='LUSTRE' && Storagecapacity >1200 ] | reverse(sort_by(@, &LustreConfiguration.PerUnitStorageThroughput))[].{Name:Tags[?Key=='Name']|[0].Value, Storagecapacity:StorageCapacity, FS_ID:FileSystemId,Type:FileSystemType, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}: invalid token: Parse error at column 58, token "1200" (NUMBER), for expression:
"FileSystems[?FileSystemType=='LUSTRE' && Storagecapacity >1200 ] | reverse(sort_by(@, &LustreConfiguration.PerUnitStorageThroughput))[].{Name:Tags[?Key=='Name']|[0].Value, Storagecapacity:StorageCapacity, FS_ID:FileSystemId,Type:FileSystemType, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}"
^
My Own Observation:
If i should look at the above error it doesn't like the comparison operation with int
value which I am providing.
Any help would be much appreciated.
CodePudding user response:
While working with json
data type, It's quite obvious that AWS for Linux and macOS you need to interpret strings literally using single quotation marks ' '
to enclose the JSON data structure and get the operator values interpreted. You need to use the command substitution(``).
So, if you use the below command it should work for you...
$ aws fsx describe-file-systems --query 'FileSystems[?StorageCapacity >`12000` && FileSystemType==`LUSTRE`]|reverse(sort_by(@, &StorageCapacity))[].{Name:Tags[?Key==`Name`]|[0].Value,FileSystemType: FileSystemType, StorageCapacity: StorageCapacity, FS_ID:FileSystemId, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}' --profile demo --output table --no-cli-pager
Now, if you look at the above syntax, it's very explicit that the complete command body is enclosed within single quotes ''
and the Value against the operators are within the command substitution (``)
IE backticks which then correctly expands its value as desired.
Result:
----------------------------------------------------------------------------------------------------------------------------------------------------
| DescribeFileSystems |
---------------------- ----------------- --------------------- ----------- ------------------------------------- ------------------ --------------
| FS_ID | FileSystemType | Maintainancewindow | Mount | Name | StorageCapacity | Throughput |
---------------------- ----------------- --------------------- ----------- ------------------------------------- ------------------ --------------
| fs-0200c83e16340020c| LUSTRE | 3:30:00 | gjiizbmv | labdemo-project1-00000001 | 271200 | 50 |
| fs-067d61e8fts63f99d| LUSTRE | 3:30:00 | s3a3fbmv | labdemo-project1-00000002 | 249600 | 200 |
| fs-01dg43bb9455b0011| LUSTRE | 3:30:00 | jg63fbmv | labdemo-project1-00000003 | 74400 | 50 |
---------------------- ----------------- --------------------- ----------- ------------------------------------- ------------------ --------------
Hope it will help, Happy learning!