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.
Topics
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
Using the following values, create an EventBridge rule based on Amazon Location events:
-
For Rule type, choose Rule with an event pattern.
-
In the Event pattern box, add the following pattern:
{ "source": ["aws.geo"], "detail-type": ["Location Geofence Event"] }
You can optionally specify only
ENTER
orEXIT
events by adding adetail
tag:{ "source": ["aws.geo"], "detail-type": ["Location Geofence Event"], "detail": { "EventType": ["ENTER"] } }
-
For 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.
It's best practice to confirm that the event rule was successfully applied or your automated action may not initiate 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" ] }
The same event may be delivered more than one time. You can use the event id to de-duplicate the events that you receive.
Amazon EventBridge event examples for Amazon Location Service
The following is an example of an event for entering a geofence initiated 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 ], "Accuracy": { "Horizontal": 15.3 }, "PositionProperties": { "ExampleKey": "ExampleField" } } }
The following is an example of an event for exiting a geofence initiated 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 ], "Accuracy": { "Horizontal": 15.3 }, "PositionProperties": { "ExampleKey": "ExampleField" } } }