AWS Location geofence tracker

0

I want to create or update a Tracker in AWS Location. If the tracker name does not exist, I want to create the tracker, otherwise I want to update the tracker. What is the best practice to achieve this? I was thinking about getting all the trackers and then determining if the tracker name in question exists. Is there a better way to do this? Here is some pseudocode of what I was thinking about to achieve this:

const trackerName = 'my-tracker-' + event.truckName;

// List all the trackers...
const location.listTrackers(params = {}, function(err, data) {
   // Logic inside the callback to determine if trackerName exists...
   if (<trackerName already exists >) {
      location.createTracker(); // create the tracker
   } else {
      location.updateTracker(); // update the tracker with vehicle position
   }  
});
jim_b
asked 2 years ago306 views
2 Answers
1

Yes, this is how you could check if a tracker exists. Alternatively you could call another operation on the tracker and see if you got a ResourceNotFoundException.

However, I am curious about what you are trying to achieve, because your code sample, mentions location.updateTracker(); // update the tracker with vehicle position. UpdateTracker is an API to update the properties of a given tracker like its description and not for updating device positions.

Can you explain a little bit more about what you are trying to do, I may be able to help... (for example, why are you creating a tracker per truck?)

AWS
answered 2 years ago
  • Perhaps updateTracker isn't the appropriate API call. I am only trying to update the position for a given truck (not the properties of a tracker).

    What I am trying to accomplish is the following: -Track the position for all of the trucks in the fleet -Link a tracker to a Geofence collection, with a couple thousand geofences in that collection -When a given truck enters or exits a geofence, I am going to use EventBridge to target a lambda to store the data for that truck

    The tracker will only live for a limited time when a truck is approaching a geofence, and then get destroyed. I want to get the specific truck information upon enter/exit a geofence in the collection. Seems to me that it would make sense to have a 1-to-1 mapping of tracker to truck.

  • Dumb question: can you track multiple vehicles with one tracker? I just looked at the API docs for "batchUpdateDevicePosition", and it looks like DeviceId is part of the parameters to Update. Would it make more sense to just have one tracker for our ~8,000 trucks?

1

Yes. You can track thousands of devices with a single tracker. BatchUpdateDevicePosition also allows you to associate 1-3 attributes with positions that you send to tracking service, and you will get them from EventBridge with the Enter/Exit events. (see PositionProperties)

In your case, you could have just one tracker and send truck specific information like the truck name with each position and use it in the lambda that will be your target for EventBridge.

Thanks,
Oren

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions