[英]AWS CLI combining operators within a single query
我正在为aws fsx describe-file-systems
运行 AWS query
命令,我想在其中组合两个运算符,其中它将查找FileSystemType=="LUSTRE"
和另一个运算符,其中Storagecapacity >1200
,然后在查询中跟进另一个内容。
为了获得结果,我尝试了以下带有错误的命令:
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
上述命令产生的错误:
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}"
^
我自己的观察:如果我应该看看上面的错误,它不喜欢我提供的与int
值的比较操作。
任何帮助将非常感激。
在处理json
数据类型时,很明显,对于 Linux 和 macOS 的 AWS,您需要使用单引号' '
逐字解释字符串,以将 JSON 数据结构括起来,并解释运算符值。 您需要使用命令替换 (``)。
所以,如果你使用下面的命令,它应该适合你......
$ 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
现在,如果您查看上面的语法,很明显完整的命令主体包含在单引号''
中,并且针对运算符的值在命令替换(``)
IE 反引号内,然后根据需要正确扩展其值.
结果:
----------------------------------------------------------------------------------------------------------------------------------------------------
| 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 |
+----------------------+-----------------+---------------------+-----------+-------------------------------------+------------------+--------------+
希望对你有所帮助,祝学习愉快!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.