簡體   English   中英

AWS CLI 在單個查詢中組合運算符

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM