Reacting to Amazon Location Service events with Amazon EventBridge - Amazon Location Service

Reacting to Amazon Location Service events with Amazon EventBridge

Amazon EventBridge is a serverless event bus that efficiently connects applications together using data from AWS services like Amazon Location. EventBridge receives geofence events from Amazon Location and routes that data to targets like AWS Lambda. You can set up routing rules to determine where to send your data to build application architectures that react in real time.

For more information, see the Events and Event Patterns in the Amazon EventBridge User Guide.

Create event rules for Amazon Location

You can create up to 300 rules per event bus in EventBridge to configure actions taken in response to an Amazon Location event.

For example, you can create a rule for geofence events where a push notification will be sent when a phone is detected within a geofenced boundary.

To create a rule for Amazon Location events

  1. Log in to AWS using an account that has permissions to use EventBridge and Amazon Location Service.

  2. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.

  3. Choose Create rule.

  4. Enter a Name for the rule, and, optionally, a description.

  5. Under Define pattern, choose Event pattern.

  6. Under Event matching pattern, choose Custom pattern.

  7. In the Event pattern box, add the following pattern that filters events by detail-type, which will be Location Geofence Event, then choose Save.

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

    You can also filter events associated with specific trackers or geofence collections by matching on the event’s detail, where the geofence EventType can be ENTER or EXIT. For example:

    { "source": [ "aws.geo" ], "detail-type": [ "Location Geofence Event" ], "detail": { "EventType": "ENTER" } }
  8. In the Select event bus section, choose AWS default event bus, and confirm that Enable the rule on the selected event bus is toggled on.

  9. Under Select targets, choose the target action to take when a geofence event is received from Amazon Location Service.

    For example, use an Amazon Simple Notification Service (SNS) topic to send an email or text message when an event occurs. You first need to create an Amazon SNS topic using the Amazon SNS console. For more information, see Using Amazon SNS for user notifications.

  10. Optionally, choose Add target to specify an additional target action for the event rule.

  11. Choose Create.

Warning

It's best practice to confirm that the event rule was successfully applied or your automated action may not trigger as expected. To verify your event rule, initiate conditions for the event rule. For example, simulate a device entering a geofenced area.

You can also capture all events from Amazon Location, by just excluding the detail-type section. For example:

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

Amazon EventBridge event examples for Amazon Location Service

The following is an example of an event for entering a geofence triggered by calling 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 ] } }

The following is an example of an event for exiting a geofence triggered by calling 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 ] } }