使用 Amazon 對 Amazon 定 Location Service 事件做出反應 EventBridge - Amazon Location Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Amazon 對 Amazon 定 Location Service 事件做出反應 EventBridge

Amazon EventBridge 是一種無伺服器事件匯流排,可使用 Amazon 位置等AWS服務的資料,有效地將應用程式連接在一起。 EventBridge 接收來自 Amazon 位置的事件,並將資料路由到類似的目標AWS Lambda。您可以設定路由規則,決定要將資料傳送到何處,以建置即時反應的應用程式架構。

只有地理圍欄事件(ENTEREXIT事件,因為設備進入或離開地理圍欄區域)被默認發送到。 EventBridge 您也可以為追蹤器資源啟用所有篩選的職位更新事件。如需詳細資訊,請參閱 啟用追蹤器的更新事件

如需詳細資訊,請參閱 Amazon EventBridge 使用者指南中的事件和事件模式

啟用追蹤器的更新事件

根據預設,Amazon 位置僅會傳送地理圍欄事件ENTEREXIT地理圍欄事件至。 EventBridge您可以為追蹤器啟用要傳送至的所有篩選職位UPDATE事件 EventBridge。您可以在建立更新追蹤器時執行此操作。

例如,若要使用更新現有的追蹤器AWS CLI,您可以使用下列命令 (使用您的追蹤器資源的名稱來取代 MyTracker)。

aws location update-tracker --tracker-name MyTracker --event-bridge-enabled

若要關閉追蹤器的位置事件,您必須使用 API 或 Amazon 定 Location Service 主控台。

為 Amazon 地點創建事件規則

您可以在每個事件匯流排中建立最多 300 個規則, EventBridge 以設定針對 Amazon 位置事件採取的動作。

例如,您可以為地理圍欄事件建立規則,當在地理圍欄邊界內偵測到電話時,將傳送推播通知。

若要建立 Amazon 位置事件的規則

使用下列值,根據 Amazon 位置事件建立 EventBridge 規則

  • 針對 Rule type (規則類型) 選擇 Rule with an event pattern (具有事件模式的規則)。

  • 在 [事件模式] 方塊中,新增下列模式:

    { "source": ["aws.geo"], "detail-type": ["Location Geofence Event"] }

    若要建立追蹤器位置更新的規則,您可以改為使用下列模式:

    { "source": ["aws.geo"], "detail-type": ["Location Device Position Event"] }

    您可以選擇通過添加detail標籤來指定僅ENTEREXIT事件(如果您的規則用於跟踪器位置更新EventType,則只有一個,因此無需對其進行過濾):

    { "source": ["aws.geo"], "detail-type": ["Location Geofence Event"], "detail": { "EventType": ["ENTER"] } }

    您也可以選擇篩選位置或地理圍欄的屬性:

    { "source": ["aws.geo"], "detail-type": ["Location Geofence Event"], "detail": { "EventType": ["ENTER"], "GeofenceProperties": { "Type": "LoadingDock" }, "PositionProperties": { "VehicleType": "Truck" } } }
  • 對於選取目標,請選擇從 Amazon 定 Location Service 收到事件時要採取的目標動作。

    例如,使用 Amazon Simple Notification Service (SNS) 主題在事件發生時傳送電子郵件或文字訊息。您首先需要使用 Amazon SNS 主控台建立 Amazon SNS 主題。如需詳細資訊,請參閱使用 Amazon SNS 取得使用者通知

警告

最佳做法是確認事件規則已成功套用,或您的自動化動作可能無法如預期般啟動。若要驗證您的事件規則,請啟動事件規則的條件。例如,模擬進入地理圍欄區域的設備。

您還可以通過排除該detail-type部分來捕獲 Amazon 位置的所有事件。例如:

{ "source": [ "aws.geo" ] }
注意

同一個事件可以傳遞一次以上。您可以使用事件 ID 來刪除接收到的事件的重複資料。

Amazon 定 Location Service 的 Amazon EventBridge 事件示例

以下是輸入通過調用發起的地理圍欄的事件的示例。BatchUpdateDevicePosition

{ "version": "0", "id": "aa11aa22-33a-4a4a-aaa5-example", "detail-type": "Location Geofence Event", "source": "aws.geo", "account": "636103698109", "time": "2020-11-10T23:43:37Z", "region": "eu-west-1", "resources": [ "arn:aws:geo:eu-west-1:0123456789101:geofence-collection/GeofenceEvents-GeofenceCollection_EXAMPLE", "arn:aws:geo:eu-west-1:0123456789101:tracker/Tracker_EXAMPLE" ], "detail": { "EventType": "ENTER", "GeofenceId": "polygon_14", "DeviceId": "Device1-EXAMPLE", "SampleTime": "2020-11-10T23:43:37.531Z", "Position": [ -123.12390073297821, 49.23433613216247 ], "Accuracy": { "Horizontal": 15.3 }, "GeofenceProperties": { "ExampleKey1": "ExampleField1", "ExampleKey2": "ExampleField2" }, "PositionProperties": { "ExampleKey1": "ExampleField1", "ExampleKey2": "ExampleField2" } } }

以下是用於退出通過調用發起的地理圍欄的事件的示例。BatchUpdateDevicePosition

{ "version": "0", "id": "aa11aa22-33a-4a4a-aaa5-example", "detail-type": "Location Geofence Event", "source": "aws.geo", "account": "123456789012", "time": "2020-11-10T23:41:44Z", "region": "eu-west-1", "resources": [ "arn:aws:geo:eu-west-1:0123456789101:geofence-collection/GeofenceEvents-GeofenceCollection_EXAMPLE", "arn:aws:geo:eu-west-1:0123456789101:tracker/Tracker_EXAMPLE" ], "detail": { "EventType": "EXIT", "GeofenceId": "polygon_10", "DeviceId": "Device1-EXAMPLE", "SampleTime": "2020-11-10T23:41:43.826Z", "Position": [ -123.08569321875426, 49.23766166742559 ], "Accuracy": { "Horizontal": 15.3 }, "GeofenceProperties": { "ExampleKey1": "ExampleField1", "ExampleKey2": "ExampleField2" }, "PositionProperties": { "ExampleKey1": "ExampleField1", "ExampleKey2": "ExampleField2" } } }

以下是透過呼叫起始的職位更新事件範例BatchUpdateDevicePosition

{ "version": "0", "id": "aa11aa22-33a-4a4a-aaa5-example", "detail-type": "Location Device Position Event", "source": "aws.geo", "account": "123456789012", "time": "2020-11-10T23:41:44Z", "region": "eu-west-1", "resources": [ "arn:aws:geo:eu-west-1:0123456789101:tracker/Tracker_EXAMPLE" ], "detail": { "EventType": "UPDATE", "TrackerName": "tracker_2", "DeviceId": "Device1-EXAMPLE", "SampleTime": "2020-11-10T23:41:43.826Z", "ReceivedTime": "2020-11-10T23:41:39.235Z", "Position": [ -123.08569321875426, 49.23766166742559 ], "Accuracy": { "Horizontal": 15.3 }, "PositionProperties": { "ExampleKey1": "ExampleField1", "ExampleKey2": "ExampleField2" } } }