除了 Cloud Assembly 中的簡單條件清單之外,還可以透過進階編輯器組合更複雜的準則運算式,以控制動作何時可用。

建立新資源動作時,請選取需要條件使用進階編輯器。然後,輸入所需的準則運算式。

自訂動作準則進階編輯器

運算式是一個子句或子句清單,每個子句均採用「索引鍵-運算子-值」格式。上圖顯示了目標必須開啟電源並且存在的準則。

子句

子句 說明 範例
所有次子句均必須為 true,運算式結果才能為 true。

僅當 properties.powerState 為 ON 且 syncStatus 不為 MISSING 時,才會評估為 true。

matchExpression:
  - and:
      - key: properties.powerState
        operator: eq
        value: ON
      - key: syncStatus
        operator: notEq
        value: MISSING
一或多個次子句必須為 true,運算式結果才能為 true。

無論 properties.powerState 為 ON 還是 OFF,均評估為 true。

matchExpression:
  - or:
      - key: properties.powerState
        operator: eq
        value: ON
      - key: properties.powerState
        operator: eq
        value: OFF

運算子

運算子 說明 範例
eq 等於。尋找完全相符項。

當 properties.powerState 為 ON 時,評估為 true。

matchExpression:
  - and:
      - key: properties.powerState
        operator: eq
        value: ON
notEq 不等於。避免完全相符項。

當 properties.powerState 不為 OFF 時,評估為 true。

matchExpression:
  - and:
      - key: properties.powerState
        operator: notEq
        value: OFF
hasAny 在物件集合中尋找相符項。

當 storage.disks 陣列包含 100 IOPS EBS 物件時,評估為 true。

matchExpression:
  - key: storage.disks
    operator: hasAny
    value:
      matchExpression: 
        - and:
            - key: iops
              operator: eq
              value: 100
            - key: service
              operator: eq
              value: ebs
in 在一組值中尋找相符項。

當 properties.powerState 為 OFF 或 SUSPEND 時,評估為 true。

matchExpression:
  - and:
      - key: properties.powerState
        operator: in
        value: OFF, SUSPEND
notIn 避免與一組值相符。

當 properties.powerState 既不為 OFF 也不為 SUSPEND 時,評估為 true。

matchExpression:
  - and:
      - key: properties.powerState
        operator: notIn
        value: OFF, SUSPEND
greaterThan 尋找高於指定臨界值的相符項。僅適用於數值。

當 storage.disks 陣列中的第一個物件的 IOPS 高於 50 時,評估為 true。

matchExpression:
  - and:
      - key: storage.disks[0].iops
        operator: greaterThan
        value: 50
lessThan 尋找低於指定臨界值的相符項。僅適用於數值。

當 storage.disks 陣列中的第一個物件的 IOPS 低於 200 時,評估為 true。

matchExpression:
  - and:
      - key: storage.disks[0].iops
        operator: lessThan
        value: 200
greaterThanEquals 尋找等於或高於指定臨界值的相符項。僅適用於數值。

當 storage.disks 陣列中的第一個物件的 IOPS 等於或高於 100 時,評估為 true。

matchExpression:
  - and:
      - key: storage.disks[0].iops
        operator: greaterThanEquals
        value: 100
lessThanEquals 尋找等於或低於指定臨界值的相符項。僅適用於數值。

當 storage.disks 陣列中的第一個物件的 IOPS 等於或低於 100 時,評估為 true。

matchExpression:
  - and:
      - key: storage.disks[0].iops
        operator: lessThanEquals
        value: 100
matchesRegex 使用規則運算式尋找相符項。

當 properties.zone 為 us-east-1a 或 us-east-1c 時,評估為 true。

matchExpression:
  - and:
      - key: properties.zone
        operator: matchesRegex
        value: (us-east-1)+(a|c){1,2}

範例

當 properties.tags 包含索引鍵為 key1 且值為 value1 的標籤時,下列準則運算式會評估為 true。

外部運算式使用 hasAny,因為 properties.tags 是一個陣列,並且您希望只要在陣列的任何索引鍵-值配對中出現 key1=value1 時就評估為 true。

在內部運算式中有兩個子句,一個用於索引鍵欄位,另一個用於值欄位。properties.tags 陣列擁有索引鍵-值標記配對,您需要同時符合索引鍵和值欄位。

matchExpression:
  - key: properties.tags
    operator: hasAny
    value:
      matchExpression:
        - and:
            - key: key
              operator: eq
              value: key1
            - key: value
              operator: eq
              value: value1

下列準則運算式類似於前一個範例,但現在只要 properties.tags 包含 key1=value1 或 key2=value2 標籤,就會評估為 true。

matchExpression:
  - or:
      - key: properties.tags
        operator: hasAny
        value:
          matchExpression:
            - and:
                - key: key
                  operator: eq
                  value: key1
                - key: value
                  operator: eq
                  value: value1
      - key: properties.tags
        operator: hasAny
        value:
          matchExpression:
            - and:
                - key: key
                  operator: eq
                  value: key2
                - key: value
                  operator: eq
                  value: value2