Block 4 — Fleet Indexing Introduction¶
Duration: 45 min
Steps¶
- Navigate to IoT Core → Settings → Fleet indexing → Manage indexing
- Enable Thing indexing and select the following data sources:
- Add thing connectivity — indexes connected/disconnected state, disconnect reason, and last connection timestamp
- Include socket information (new) — indexes source IP, source port, target IP, target port, and VPC endpoint ID per connection
- Add named shadows — add
device-configanddevice-health - Add device software packages and versions — indexes the reserved
$packageshadow for version-targeted queries
-
Click Update and wait for index status to show
ACTIVE.AWS CLI equivalent
aws iot update-indexing-configuration \ --thing-indexing-configuration \ 'thingIndexingMode=REGISTRY_AND_SHADOW,thingConnectivityIndexingMode=STATUS,namedShadowIndexingMode=ON,filter={namedShadowNames=["device-config","device-health","app-deployment","$package"]}' echo "UPDATE_OK"This mirrors the account-wide config the platform stack already applies on deploy (including the
app-deploymentshadow added in Session 3) — re-running it here is idempotent and safe against a live shared slot. It requiresiot:UpdateIndexingConfigurationon your own account — a locked-down CI role without that permission will fail this step even though a workshop participant's own account will not.Check status:
-
Navigate to IoT Core → Manage → Things → Advanced thing search and confirm all devices are visible.
Console tip: The regular Things search bar uses a display-name dialect that doesn't support shadow/connectivity queries. Use Advanced thing search instead — it accepts the same Lucene syntax as the CLI and the links below pre-populate the query for you.
-
Scope to your deployment — filter by the
deploymentIdattribute so subsequent queries only return your three devices:AWS CLI equivalent
Note: Thing names are EC2 instance IDs, not slot-prefixed —
attributes.deploymentIdis the right field to scope to your slot. Combine it with any other filter usingAND, e.g.attributes.deploymentId:ws-slot00 AND connectivity.connected:true. -
Query by shadow state — print the reported
config_version(from thedevice-configshadow) andtelemetry-agentversion (from the reserved$packageshadow) for each device, side by side:aws iot search-index --index-name AWS_Things \ --query-string 'attributes.deploymentId:ws-slot00' \ | jq -r '["THING","CONNECTED","CONFIG_VERSION","TELEMETRY_AGENT"], (.things[] | (.shadow // "{}" | fromjson) as $s | ($s.name["$package"].reported // {}) as $pkg | [ .thingName, (if .connectivity.connected then "online" else "offline" end), ($s.name["device-config"].reported.config_version // "—"), ($pkg["ws-slot00-telemetry-agent"].version // $pkg["telemetry-agent"].version // "—") ] ) | @tsv' | column -tA device that hasn't reported a given shadow yet (e.g. one still
QUEUEDin a staged rollout, or never provisioned with a$packageshadow) has anullshadowfield. Piping that straight intofromjsonaborts the whole pipeline (jq: error … null (null) only strings can be parsed) after just the first few rows — so the fallbacks are load-bearing:.shadow // "{}"parses a missing shadow as an empty object, and each// "—"fills in for a field the device hasn't reported. Without them you only see the handful of devices before the first gap.The
TELEMETRY_AGENTlookup is deliberately two-pronged. The reserved$packageshadow keys each entry by package name, so the version that IoT Jobs writes on a package-linked deployment lands underws-slot00-telemetry-agent, not a baretelemetry-agent. Devices updated by an earlier hand-writing handler (before package deployment existed) instead carry a baretelemetry-agentkey. A device that has run the block-2 job shows both — the frozen hand-written1.0.0and the package-managed2.0.0— so the query readsws-slot00-telemetry-agentfirst and only falls back to the bare key. Reading the bare key alone is the classic "the job succeeded but the version still says v1" trap: the package-managed value is right there under a different key.Output — one row per device:
THING CONNECTED CONFIG_VERSION TELEMETRY_AGENT i-012cb542a8cd2ad6b online 2.0.0 2.0.0 i-0a661fd3a5c46da02 online 2.0.0 2.0.0 i-0233f0350a555411c offline 1.0.0 —Note: Fleet-indexing search is a filter, not a projection — a Lucene query like
config_version:*only decides which Things match; it can't make the search return a field value. Both versions ride along inside each matched Thing's shadow document, so we pull them out withjqclient-side. In the console you'd instead open a single Thing → Device Shadows and read thedevice-configand$packageshadows one at a time. To do a yes/no rollout check on the fleet instead, add the version to the query itself, e.g.... AND shadow.name.device-config.reported.config_version:2.0.0. -
Query connectivity status:
Discussion Questions¶
- What is the difference between a static Thing Group and a Dynamic Thing Group?
- How would you target a job at "all devices still on
telemetry-agentv1.0.0"? (Hint: use the reserved$packageshadow as the Dynamic Thing Group filter —attributes.deploymentId:ws-slot00 AND shadow.name.$package.reported.telemetry-agent.version:1.0.0.) - What's the eventual-consistency caveat with Dynamic Thing Groups? (Group membership evaluates asynchronously — newly registered devices may take seconds to appear.)
- What does socket indexing let you do that plain connectivity indexing doesn't? (Answer: pinpoint which source IPs/ports are connecting — useful for diagnosing NAT traversal issues or spotting devices connecting from unexpected networks.)
Wrap-Up¶
Recap the full Session 1 data path:
EC2 (IoT Device Client)
→ MQTT publish → IoT Core
→ IoT Rules Engine → Kafka action → MSK
→ Amazon Data Firehose (Iceberg destination) → S3
→ Athena (Glue catalog)
Preview Session 2: Next week you'll use IoT Jobs to push a script update to all 3 devices simultaneously — changing telemetry frequency from 0.2 Hz to 1 Hz and adding network I/O metrics.