Skip to content

Block 4 — Fleet Indexing Introduction

Duration: 45 min


Steps

  1. Navigate to IoT Core → Settings → Fleet indexing → Manage indexing
  2. 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-config and device-health
    • Add device software packages and versions — indexes the reserved $package shadow for version-targeted queries
  3. 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-deployment shadow added in Session 3) — re-running it here is idempotent and safe against a live shared slot. It requires iot:UpdateIndexingConfiguration on 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:

    aws iot describe-index --index-name AWS_Things
    

  4. 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.

  1. Scope to your deployment — filter by the deploymentId attribute so subsequent queries only return your three devices:

    Open in console

    AWS CLI equivalent

    aws iot search-index --index-name AWS_Things \
      --query-string 'attributes.deploymentId:ws-slot00'
    

    Note: Thing names are EC2 instance IDs, not slot-prefixed — attributes.deploymentId is the right field to scope to your slot. Combine it with any other filter using AND, e.g. attributes.deploymentId:ws-slot00 AND connectivity.connected:true.

  2. Query by shadow state — print the reported config_version (from the device-config shadow) and telemetry-agent version (from the reserved $package shadow) 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 -t
    

    A device that hasn't reported a given shadow yet (e.g. one still QUEUED in a staged rollout, or never provisioned with a $package shadow) has a null shadow field. Piping that straight into fromjson aborts 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_AGENT lookup is deliberately two-pronged. The reserved $package shadow keys each entry by package name, so the version that IoT Jobs writes on a package-linked deployment lands under ws-slot00-telemetry-agent, not a bare telemetry-agent. Devices updated by an earlier hand-writing handler (before package deployment existed) instead carry a bare telemetry-agent key. A device that has run the block-2 job shows both — the frozen hand-written 1.0.0 and the package-managed 2.0.0 — so the query reads ws-slot00-telemetry-agent first 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 with jq client-side. In the console you'd instead open a single Thing → Device Shadows and read the device-config and $package shadows 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.

  3. Query connectivity status:

    Open in console

    AWS CLI equivalent

    aws iot search-index --index-name AWS_Things \
      --query-string 'attributes.deploymentId:ws-slot00 AND connectivity.connected:true'
    


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-agent v1.0.0"? (Hint: use the reserved $package shadow 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.


Reference