すべてのプロダクト
Search
ドキュメントセンター

ApsaraMQ for MQTT:イベントパターン

最終更新日:Jan 14, 2025

イベントパターンは、EventBridge がイベントをフィルタリングするために提供するモジュールです。 EventBridge は、イベントパターンを使用してイベントをフィルタリングし、イベントターゲットにルーティングします。イベントパターンは、一致するイベントと同じ構造である必要があります。このトピックでは、一般的なイベントパターンについて説明します。

使用方法

イベントパターンを使用する場合は、以下の点に注意してください。

  • 一致するイベントには、イベントパターンにリストされているすべてのフィールドが含まれている必要があり、イベント内のフィールドはイベントパターン内のフィールドと同じネスト構造である必要があります。

  • イベントパターンの各文字に対して完全一致が使用されます。すべての文字は大文字と小文字が区別されます。 EventBridge は、一致処理中に文字列を変更しません。

  • 一致するイベントのすべての値は JSON 形式である必要があります。これらの値には、数値、二重引用符( "" )で囲まれた文字列、truefalsenull など、二重引用符( "" )で囲まれていないキーワードが含まれます。

  • イベントパターンは OR 論理演算子をサポートしています。イベントパターンで キー を指定するには AND 論理演算子を使用し、配列で キー 値を指定するには OR 論理演算子を使用できます。

フィールド値に基づくイベントマッチング

特定のフィールドの値を一致条件として指定できます。次の例では、source フィールドの値がオブジェクトストレージサービス( OSS )を示すイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "source":[
        "acs.oss" // OSS からのイベントのみをフィルタリング
    ]
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

フィールド値のプレフィックスに基づくイベントマッチング

フィールド値のプレフィックスを一致条件として指定できます。次の例では、source フィールドの値が acs. で始まるイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "source":[
        {
            "prefix":"acs." // acs. で始まるイベントソースをフィルタリング
        }
    ]
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

フィールド値の包含に基づくイベントマッチング

イベントマッチングに含めるフィールド値を指定できます。次のセクションでは、2 つの例について説明します。例 1 では、type フィールドの値に Normal が含まれるイベントのみが一致してフィルタリングされます。例 2 では、type フィールドの値に Normal または Error が含まれるイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

例 1: "type" フィールドの値に "Normal"

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserNormalEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
  "type":[
    {
      "contains": "Normal" //"Normal" を含む type フィールドをフィルタリング
    }
  ]
}

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserNormalEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserErrorEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.png",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

なし

例 2: "type" フィールドの値に "Normal" または "Error"

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserNormalEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
  "type":[
    {
      "contains": "Normal" // "Normal" または "Error" を含む type フィールドをフィルタリング
    },
    {
      "contains": "Error"
    }
  ]
}

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserNormalEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserErrorEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.png",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserErrorEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.png",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"UserOtherEvent",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.png",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

なし

フィールド値のサフィックスに基づくイベントマッチング

フィールド値のサフィックスを一致条件として指定できます。次の例では、subject フィールドの値が acs:oss:cn-hangzhou:1234567:xls-papk/ で始まり、.jpg または .txt で終わるイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "subject":[
        {
            "prefix":"acs:oss:cn-hangzhou:1234567:xls-papk/" // 指定されたプレフィックス
        },
        {
            "suffix":".txt" // .txt または .jpg で終わる subject フィールドをフィルタリング
        },
        {
            "suffix":".jpg"
        }
    ]
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.png",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{ // .png で終わるため、フィルタリング対象外
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.png",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

フィールド値の除外に基づくイベントマッチング

イベントマッチングから除外するフィールド値を指定できます。 anything-but フィールドを使用して、文字列と数値を除外できます。次の例では、state フィールドの値が initializing でなく、x-limit フィールドの値が 123 でないイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

次のパターンは、anything-but フィールドを使用して、1 つの文字列と 1 つの数値を除外します。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"running",
        "x-limit":456
    }
}
{
    "data":{
        "state":[
            {
                "anything-but":"initializing" // state が initializing でないイベントをフィルタリング
            }
        ],
        "x-limit":[
            {
                "anything-but":123 // x-limit が 123 でないイベントをフィルタリング
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"running",
        "x-limit":456
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":456 // state フィールドがないため、フィルタリング対象外
    }
}

なし

次の例では、state フィールドの値が stopped または overloaded でないイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"terminated"
    }
}
{
    "data":{
        "state":[
            {
                "anything-but":[
                    "stopped", // state が stopped または overloaded でないイベントをフィルタリング
                    "overloaded"
                ]
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"terminated"
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "datas"dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"stopped" // state が stopped のため、フィルタリング対象外
    }
}

なし

次の例では、x-limit フィールドの値が 100200、または 300 でないイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":456
    }
}
{
    "data":{
        "x-limit":[
            {
                "anything-but":[
                    100, // x-limit が 100、200、または 300 でないイベントをフィルタリング
                    200,
                    300
                ]
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":456
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":200 // x-limit が 200 のため、フィルタリング対象外
    }
}

なし

次の例では、state フィールドの値が init で始まらないイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"pending"
    }
}
{
    "data":{
        "state":[
            {
                "anything-but":{
                    "prefix":"init" // state が init で始まらないイベントをフィルタリング
                }
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"pending"
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"initializing" // state が initializing のため、フィルタリング対象外
    }
}

なし

次の例では、source フィールドの値が Elastic Compute Service を示さないイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":456
    }
}
{
    "source":[
        {
            "anything-but":[
                "acs.ecs" // source が acs.ecs でないイベントをフィルタリング
            ]
        }
    ]
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":456
    }
}
{
    "id": "45ef4dewdwe1-7c35-447a-bd93-fab****",
    "source": "acs.ecs", // source が acs.ecs のため、フィルタリング対象外
    "specversion": "1.0",
    "subject": "acs.ecs:cn-hangzhou:123456789098****:215672",
    "time": "2020-11-19T21:04:41Z",
    "type": "ecs:Disk:ConvertToPostpaidCompleted",
    "aliyunaccountid": "123456789098****",
    "aliyunpublishtime": "2020-11-19T21:04:42Z",
    "aliyuneventbusname": "default",
    "aliyunregionid": "cn-hangzhou",
    "aliyunpublishaddr": "172.25.XX.XX",
    "data": {
        "result": "accomplished",
        "diskName": "e2e-ecs-xxxxxxxx",
        "diskId": "d-gx3hn2vc0fxxxxxxxx"
    }
}

なし

次の例では、source フィールドの値が Alibaba Cloud サービスを示さないイベントのみが一致してフィルタリングされます。この場合、カスタムアプリケーションから送信されたイベントが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss", // source が acs. で始まるため、フィルタリング対象外
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "x-limit":456
    }
}
{
    "source":[
        {
            "anything-but":{
                "prefix":"acs." // acs. で始まらないイベントソースをフィルタリング
            }
        }
    ]
}

なし

数値または範囲に基づくイベントマッチング

フィールドに数値または範囲を一致条件として指定できます。次の例では、c-count フィールドの値が 0 より大きく 5 以下のイベント、d-count フィールドの値が 10 未満のイベント、x-limit フィールドの値が 301.8 のイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "c-count":5,
        "d-count":7,
        "x-limit":301.8
    }
}
{
    "data":{
        "c-count":[
            {
                "numeric":[
                    ">", // 0 より大きく、5 以下
                    0,
                    "<=",
                    5
                ]
            }
        ],
        "d-count":[
            {
                "numeric":[
                    "<", // 10 未満
                    10
                ]
            }
        ],
        "x-limit":[
            {
                "numeric":[
                    "=", // 301.8 と等しい
                    301.8
                ]
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "c-count":5,
        "d-count":7,
        "x-limit":301.8
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "c-count":5,
        "d-count":7,
        "x-limit":300 // x-limit が 300 のため、フィルタリング対象外
    }
}

なし

重要

数値の一致は、数値が JSON 形式で -1.0e9 から +1.0e9 の範囲内にある場合にのみ有効です。これらの数値は、15 桁と小数点以下 6 桁まで正確です。

IP アドレスに基づくイベントマッチング

data パラメーターのフィールドを使用して、 IP アドレスを一致条件として指定できます。次の例では、source-ip フィールドの値が 10.0.0.0/24 であるイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "source-ip":"10.0.0.123"
    }
}
{
    "data":{
        "source-ip":[
            {
                "cidr":"10.0.0.0/24" // 10.0.0.0/24 の CIDR ブロックに含まれる source-ip をフィルタリング
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "source-ip":"10.0.0.123"
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "source-ip":"192.168.0.123" // source-ip が 192.168.0.123 のため、フィルタリング対象外
    }
}

なし

説明

このタイプのイベントマッチングでは、 IPv4 アドレスのみがサポートされています。

組み合わせ条件に基づくイベントマッチング

複数 のフィルタールールを組み合わせて、一致条件として使用できます。これにより、イベントを正確に一致させてフィルタリングできます。次の例では、プレフィックスマッチング、除外マッチング、 IP アドレスマッチング、および数値マッチングが組み合わされています。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "c-count":5,
        "d-count":7,
        "x-limit":301.8,
        "state":"pending",
        "source-ip":"10.0.0.123"
    }
}
{
    "source":[
        {
            "prefix":"acs." // acs. で始まる source
        }
    ],
    "data":{
        "state":[
            {
                "anything-but":"initializing" // initializing でない state
            }
        ],
        "source-ip":[
            {
                "cidr":"10.0.0.0/24" // 10.0.0.0/24 の CIDR ブロックに含まれる source-ip
            }
        ],
        "c-count":[
            {
                "numeric":[
                    ">", // 0 より大きく、5 以下の c-count
                    0,
                    "<=",
                    5
                ]
            }
        ],
        "d-count":[
            {
                "numeric":[
                    "<", // 10 未満の d-count
                    10
                ]
            }
        ],
        "x-limit":[
            {
                "anything-but":[
                    100, // 100、200、または 300 でない x-limit
                    200,
                    300
                ]
            }
        ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "c-count":5,
        "d-count":7,
        "x-limit":301.8,
        "state":"pending",
        "source-ip":"10.0.0.123"
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "c-count":5,
        "d-count":7,
        "x-limit":301.8,
        "state":"initializing", // state が initializing のため、フィルタリング対象外
        "source-ip":"192.168.0.123" // source-ip が 192.168.0.123 のため、フィルタリング対象外
    }
}

なし

配列に基づくイベントマッチング

イベントパターンの各フィールドの値は、1 つ以上の値を含む配列です。配列内の値がイベント内の値と一致する場合、イベントは一致してフィルタリングされます。イベント内の値も配列であり、イベント内の配列とイベントパターン内の配列の共通部分が空集合でない場合、イベントは一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "subject":[
        "acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg", // subject が配列内の値と一致
        "acs:oss:cn-hangzhou:1112223:xls-papk/game_apk/123.jpg",
        "acs:oss:cn-hangzhou:4455667:xls-papk/game_apk/123.jpg"
    ]
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":[
        "acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg", // subject が配列であり、イベントパターン内の配列との共通部分が空集合でない
        "acs:acs.aliyuncvc:cn-hangzhou:<yourAccountId>:215672"
    ],
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
{ // イベントの subject 配列との共通部分が存在
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":[
        "acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
        "acs:acs.aliyuncvc:cn-hangzhou:<yourAccountId>:215672"
    ],
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

null 値または空の文字列に基づくイベントマッチング

フィールドに null 値または空の文字列を一致条件として指定できます。次の例では、eventVersion フィールドの値が空の文字列であるイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
  "version": "0",
  "id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
  "datacontenttype": "Instance Launch Successful",
  "source": "acs.oss",
  "account": "123456789012",
  "time": "2015-11-11T21:31:47Z",
  "region": "cn-hangzhou",
  "resources": [
   ],
  "data": {
    "eventVersion": "",
    "responseElements": null
   }
}
{
    "data":{
        "eventVersion":[
            "" // 空の文字列と一致
        ]
    }
}
{
  "version": "0",
  "id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
  "datacontenttype": "Instance Launch Successful",
  "source": "acs.oss",
  "account": "123456789012",
  "time": "2015-11-11T21:31:47Z",
  "region": "cn-hangzhou",
  "resources": [
   ],
  "data": {
    "eventVersion": "",
    "responseElements": null
   }
}
{
  "version": "0",
  "id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
  "datacontenttype": "Instance Launch Successful",
  "source": "acs.oss",
  "account": "123456789012",
  "time": "2015-11-11T21:31:47Z",
  "region": "cn-hangzhou",
  "resources": [
   ],
  "data": {
    "eventVersion": "1.0", // eventVersion が 1.0 のため、フィルタリング対象外
    "responseElements": null
   }
}

なし

次の例では、responseElements フィールドの値が null であるイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
  "version": "0",
  "id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
  "datacontenttype": "Instance Launch Successful",
  "source": "acs.oss",
  "time": "2015-11-11T21:31:47Z",
  "region": "cn-hangzhou",
  "resources": [
   ],
  "data": {
    "eventVersion": "",
    "responseElements": null
   }
}
{
    "data":{
        "responseElements":[
            null // null 値と一致
        ]
    }
}
{
  "version": "0",
  "id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
  "datacontenttype": "Instance Launch Successful",
  "source": "acs.oss",
  "time": "2015-11-11T21:31:47Z",
  "region": "cn-hangzhou",
  "resources": [
   ],
  "data": {
    "eventVersion": "",
    "responseElements": null
   }
}
{
  "version": "0",
  "id": "7adc8c1a-645d-4476-bdef-5d6fb57f****",
  "datacontenttype": "Instance Launch Successful",
  "source": "acs.oss",
  "account": "123456789012",
  "time": "2015-11-11T21:31:47Z",
  "region": "cn-hangzhou",
  "resources": [
   ],
  "data": {
    "eventVersion": "",
    "responseElements": "lss" // responseElements が lss のため、フィルタリング対象外
   }
}

なし

説明

null 値は空の文字列とは異なります。イベントパターンを使用して空の文字列と一致させる場合、 null 値は一致しません。

フィールドの有無に基づくイベントマッチング

data パラメーターにフィールドが存在するかどうかの条件を指定できます。次の例では、state フィールドが存在しないイベントのみが一致してフィルタリングされます。次の表は、イベントソースからイベントが送信され、イベントパターンによってフィルタリングされるプロセスを示しています。

イベントソースからのイベント

イベントパターン

フィルタリング後のイベント

{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
    }
}
{
    "data":{
        "state":[
            {
               "exists": false // state フィールドが存在しない
            }
         ]
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
    }
}
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://example.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "data":{
        "name":"test",
        "scope":100,
        "state":"terminated" // state フィールドが存在するため、フィルタリング対象外
    }
}

なし