Guide · Amazon Location Service · Device Tracking

Amazon Location Service Device Tracking for MCP Servers — BatchUpdateDevicePositionCommand, Position History

Amazon Location Service trackers store device position history and serve as the source-of-truth for where a fleet of devices, vehicles, or users has been. MCP servers use trackers to ingest GPS coordinates from IoT devices or mobile clients, serve "where is device X right now" queries, replay historical movement, and trigger geofence entry/exit events automatically when a tracker is associated with a geofence collection. This guide covers tracker creation, the BatchUpdateDevicePositionCommand ingestion pattern, position history queries, and the tracker-collection association that powers automatic EventBridge events.

TL;DR

Create a tracker resource (once, persistent). Ingest positions with BatchUpdateDevicePositionCommand — up to 10 device updates per call, each with a DeviceId, [longitude, latitude] position, and SampleTime timestamp. Query latest position with GetDevicePositionCommand. Query history with GetDevicePositionHistoryCommand (paginated, 30-day default retention). List all current positions with ListDevicePositionsCommand. Associate with a geofence collection via AssociateTrackerConsumerCommand to get automatic EventBridge entry/exit events on every position update.

Tracker use cases for MCP servers

Trackers sit between position producers (mobile apps, IoT devices, embedded GPS) and position consumers (MCP tools, dashboards, geofence evaluators). MCP servers interact with trackers in two modes:

Creating a tracker

A tracker is a named persistent resource with a configurable position filtering strategy:

import {
  LocationClient,
  CreateTrackerCommand,
  PositionFiltering,
} from "@aws-sdk/client-location";

const location = new LocationClient({ region: "us-east-1" });

await location.send(new CreateTrackerCommand({
  TrackerName: "my-mcp-tracker",
  Description: "Device position tracker for MCP server fleet tools",
  PositionFiltering: PositionFiltering.TIME_BASED,
  // PositionFiltering options:
  // "TimeBased"      — store every update (default, highest granularity)
  // "DistanceBased"  — deduplicate updates within 30m; reduces storage and geofence eval costs
  // "AccuracyBased"  — deduplicate based on accuracy radius overlap
  KmsKeyId: undefined,   // optional KMS key for position data encryption
  Tags: { "mcp-server": "true" },
}));

PositionFiltering modes

Mode Behavior Best for
TimeBased Stores every update regardless of movement High-accuracy scenarios; stationary device monitoring
DistanceBased Skips updates within 30 meters of the last stored position Mobile apps; reduces costs for slow-moving assets
AccuracyBased Skips updates whose accuracy circle overlaps the last stored position GPS devices with variable accuracy (urban canyons, indoor)

DistanceBased filtering significantly reduces costs for fleet tracking: a vehicle parked for 2 hours sending a position every 30 seconds generates 240 updates — with distance filtering, only the first position is stored. This also reduces geofence evaluation charges if the tracker has associated collections.

Ingesting device positions

BatchUpdateDevicePositionCommand accepts up to 10 device updates per call:

import {
  BatchUpdateDevicePositionCommand,
  type DevicePositionUpdate,
} from "@aws-sdk/client-location";

const updates: DevicePositionUpdate[] = [
  {
    DeviceId: "truck-001",                     // any string identifier
    Position: [-122.3321, 47.6062],            // [longitude, latitude]
    SampleTime: new Date("2026-11-15T10:00:00Z"),
    PositionProperties: {                       // optional key-value metadata
      "speed_kmh": "65",
      "heading": "northwest",
    },
    Accuracy: {
      Horizontal: 15,  // meters; used by AccuracyBased filtering
    },
  },
  {
    DeviceId: "truck-002",
    Position: [-87.6298, 41.8781],
    SampleTime: new Date("2026-11-15T10:00:05Z"),
  },
];

const result = await location.send(new BatchUpdateDevicePositionCommand({
  TrackerName: "my-mcp-tracker",
  Updates: updates,
}));

for (const error of result.Errors ?? []) {
  console.error("Failed update for device:", error.DeviceId, error.Error?.Code, error.Error?.Message);
}

Timestamp ordering requirement: SampleTime must be greater than or equal to the timestamp of the last stored position for that device. Submitting out-of-order timestamps (e.g., replaying historical data in arbitrary order) causes BatchUpdateDevicePositionCommand to silently discard the out-of-order updates — they appear in the Errors array with code AccessDeniedException or are silently filtered depending on the error type. Always sort updates by SampleTime ascending before ingesting.

Querying the latest device position

Use GetDevicePositionCommand for the most recent position of a single device:

import { GetDevicePositionCommand } from "@aws-sdk/client-location";

const latest = await location.send(new GetDevicePositionCommand({
  TrackerName: "my-mcp-tracker",
  DeviceId: "truck-001",
}));

if (latest.Position) {
  const [lon, lat] = latest.Position;  // [longitude, latitude]
  console.log("Device truck-001:");
  console.log("  Lat:", lat, "Lon:", lon);
  console.log("  As of:", latest.ReceivedTime?.toISOString());
  console.log("  Sample time:", latest.SampleTime?.toISOString());
  console.log("  Properties:", latest.PositionProperties);
}

ReceivedTime is when the server received the update; SampleTime is the timestamp you submitted with the position (the GPS measurement time). For fresh tracking, compare SampleTime against the current time to detect stale devices — a vehicle whose last SampleTime is 30 minutes ago may have connectivity issues.

Querying position history

GetDevicePositionHistoryCommand returns a time-ordered history of positions for one device (paginated, 30-day default retention):

import { GetDevicePositionHistoryCommand } from "@aws-sdk/client-location";

const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);

async function* deviceHistory(
  client: LocationClient,
  trackerName: string,
  deviceId: string,
  startTime: Date,
  endTime: Date,
) {
  let nextToken: string | undefined;
  do {
    const resp = await client.send(new GetDevicePositionHistoryCommand({
      TrackerName: trackerName,
      DeviceId: deviceId,
      StartTimeInclusive: startTime,
      EndTimeExclusive: endTime,
      MaxResults: 100,
      NextToken: nextToken,
    }));
    yield* resp.DevicePositions ?? [];
    nextToken = resp.NextToken;
  } while (nextToken);
}

for await (const pos of deviceHistory(location, "my-mcp-tracker", "truck-001", twoHoursAgo, new Date())) {
  const [lon, lat] = pos.Position!;
  console.log(pos.SampleTime?.toISOString(), lat, lon);
}

Position history supports filtering by time range. Without StartTimeInclusive and EndTimeExclusive, the command returns the full stored history up to the 30-day retention limit. For MCP tools that reconstruct a route or audit trail, use a narrow time window to bound the response size.

Listing all current device positions

ListDevicePositionsCommand returns the most recent position for every device in the tracker — useful for fleet overview tools:

import { ListDevicePositionsCommand } from "@aws-sdk/client-location";

async function* allDevicePositions(client: LocationClient, trackerName: string) {
  let nextToken: string | undefined;
  do {
    const resp = await client.send(new ListDevicePositionsCommand({
      TrackerName: trackerName,
      MaxResults: 100,
      NextToken: nextToken,
    }));
    yield* resp.Entries ?? [];
    nextToken = resp.NextToken;
  } while (nextToken);
}

for await (const device of allDevicePositions(location, "my-mcp-tracker")) {
  const [lon, lat] = device.Position!;
  const ageMs = Date.now() - (device.SampleTime?.getTime() ?? 0);
  const ageMin = Math.round(ageMs / 60000);
  console.log(device.DeviceId, lat.toFixed(5), lon.toFixed(5), `${ageMin}m ago`);
}

Tracker-to-geofence-collection association

Once a tracker is associated with a geofence collection, every BatchUpdateDevicePositionCommand call automatically evaluates the new position against all geofences in the associated collection. Amazon Location Service emits an EventBridge Location Geofence Event for each boundary crossing — no explicit BatchEvaluateGeofencesCommand call required:

import { AssociateTrackerConsumerCommand } from "@aws-sdk/client-location";

// Get the geofence collection ARN
const collectionArn = "arn:aws:geo:us-east-1:123456789012:geofence-collection/my-mcp-geofences";

await location.send(new AssociateTrackerConsumerCommand({
  TrackerName: "my-mcp-tracker",
  ConsumerArn: collectionArn,
}));

A tracker can be associated with multiple geofence collections. Each association is evaluated on every position update. To list current associations:

import { ListTrackerConsumersCommand } from "@aws-sdk/client-location";

const consumers = await location.send(new ListTrackerConsumersCommand({
  TrackerName: "my-mcp-tracker",
}));
console.log("Associated collections:", consumers.ConsumerArns);

Position data retention and deletion

Trackers retain position history for 30 days by default. To delete a specific device's history (GDPR right-to-erasure, end-of-contract cleanup):

import { DeleteDevicePositionHistoryCommand } from "@aws-sdk/client-location";

await location.send(new DeleteDevicePositionHistoryCommand({
  TrackerName: "my-mcp-tracker",
  DeviceIds: ["truck-001", "truck-002"],  // up to 10 device IDs per call
}));

IAM policy for tracker operations

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "TrackerIngestion",
      "Effect": "Allow",
      "Action": ["geo:BatchUpdateDevicePosition"],
      "Resource": "arn:aws:geo:us-east-1:123456789012:tracker/my-mcp-tracker"
    },
    {
      "Sid": "TrackerQuery",
      "Effect": "Allow",
      "Action": [
        "geo:GetDevicePosition",
        "geo:GetDevicePositionHistory",
        "geo:ListDevicePositions"
      ],
      "Resource": "arn:aws:geo:us-east-1:123456789012:tracker/my-mcp-tracker"
    }
  ]
}

Separate ingestion and query permissions: IoT devices or mobile clients that submit GPS pings need only geo:BatchUpdateDevicePosition. MCP server query tools need the read permissions. Reserve geo:AssociateTrackerConsumer and geo:DeleteDevicePositionHistory for administrative roles.

Pricing

For a fleet of 20 vehicles tracked continuously, monthly tracking cost is approximately 20 devices × 30 days = 600 device-days at $0.085 = $51/month, minus the 100 free tier = $42.65/month. This is well below commercial fleet tracking APIs at comparable precision.