Introducing a new way to review your PRs.

Read the announcement

floci-io / floci

Light, fluffy, and always free - The AWS Local Emulator alternative

View on GitHub

38 documents · Updated Nov 23, 2026

docs / svc-iot

AWS IoT device connectivity

AWS IoT device connectivity provides shared device identity, authorization, state, and message paths. It lets service APIs and MQTT clients work with the same things, certificates, policies, shadows, retained messages, topic rules, and fleet search results. For related request and identity context, see IAM and authentication; Lambda-backed authorizers use the Lambda service, and downstream workflow behavior is described with EventBridge and Step Functions. Child pages can describe specialized IoT protocol and authorization behavior when they are introduced.

Service boundary

Resource state

The IoT service manages device resources as shared AWS-style state. Things describe devices. Certificates identify them. Policies grant connection rights. Attachments connect these objects. Shadows, retained messages, jobs, thing types, thing groups, and topic rules extend the device model without changing the basic connection decision.

Control APIs create and update this state. IoT Data APIs use it for shadows, publishes, retained messages, and live connection operations. Region and account context applies to normal API requests. A device connection instead starts with the certificate identity because it has no signed request context.

References: src/…/IotService.java• L112-140 src/…/IotService.java• L245-275 src/…/IotService.java• L369-426 src/…/IotService.java• L1252-1383

API surfaces

The service exposes control-plane and data-plane APIs. Control-plane routes manage things, certificates, policies, principals, thing types, thing groups, jobs, authorizers, fleet indexes, domain configurations, and rules. IoT Data routes manage shadows, publishes, retained messages, and live MQTT sessions. MQTT clients use the broker, but broker events enter the same publish path as HTTP data requests.

The data API also exposes shadow access, named-shadow listing, retained-message access, live connection inspection and deletion, subscription listing, and direct messages. A publish request resolves its region only from usable SigV4 authorization; an unsigned or non-SigV4 request has no region context. This shared path keeps retained messages, reserved topics, publish records, and topic rules consistent across transports. CloudFormation can create IoT resources through the same service contracts.

References: src/…/IotController.java• L64-108 src/…/IotController.java• L144-412 src/…/IotController.java• L785-885 src/…/IotDataController.java• L43-190 src/…/IotAuthorizerController.java• L49-124 src/…/IotDomainConfigurationController.java• L50-108

Domain configuration state

An IoT domain configuration describes how an IoT endpoint is presented for a service type. It can hold a customer-managed domain, server certificate reference, TLS settings, authentication type, application protocol, and authorizer settings. The configuration state is separate from the broker listener, so creating or updating it does not move the endpoint.

Each region exposes AWS-managed endpoint configurations for data, jobs, and credential-provider services. These configurations are enabled and cannot be deleted. A customer-managed configuration must be disabled before deletion, while status and authorizer settings can be updated through the domain-configuration API.

References: src/…/IotDomainConfigurationService.java• L32-55 src/…/IotDomainConfigurationService.java• L82-128 src/…/IotDomainConfigurationService.java• L137-193 src/…/IotDomainConfigurationService.java• L277-317 src/…/IotDomainConfiguration.java• L11-29

V2 logging options

V2 logging options store the regional settings that control IoT service logging. The settings identify the logging role, select a default log level, and can disable all logs. The API supports partial updates after the first setup, so omitted values keep their earlier state.

The first setup requires both a role ARN and a default log level. The supported levels are DEBUG, INFO, ERROR, WARN, and DISABLED. A region without saved options returns a not-configured result rather than an empty default.

References: src/…/IotLoggingController.java• L17-47 src/…/IotLoggingService.java• L23-65 src/…/IotV2LoggingOptions.java• L5-6

Device authentication

Certificate identity

An IoT certificate is the device identity used by the TLS MQTT path. The service can issue a certificate and key pair, sign a certificate from a certificate signing request, or register an existing certificate without checking its issuing authority. The private key from a generated pair is returned once and is not kept in the stored certificate record.

The certificate ID is the lower-case SHA-256 fingerprint of the certificate's encoded form. A device is trusted because that certificate is registered in IoT state. The certificate must also be active and within its validity period when the device connects. Registered certificates report their certificate mode, with SNI_ONLY for certificates registered without a CA.

References: src/…/IotService.java• L369-483 src/…/IotController.java• L158-232 src/…/IotCertificate.java• L9-21

Connection authorization

The TLS MQTT listener asks for a client certificate and checks it when the MQTT CONNECT arrives. It finds the registered certificate, checks status and validity, then evaluates default versions of policies attached to that certificate for iot:Connect on the requested client ID.

The policy decision can use the client ID, source address, requested domain name, and thing data when the certificate is attached to a thing with that client ID. A missing policy denies the connection. An explicit deny overrides an allow. After connection, the same policy context controls Publish, Subscribe, and Receive actions on MQTT topics.

The certificate lookup has no account context at connection time. The service searches registered certificates across account partitions. It refuses a certificate registered in more than one account instead of choosing one account.

The connection decision moves through the same high-level stages for an X.509 device.

flowchart LR
    C[Device CONNECT on TLS] --> X[Registered certificate]
    X --> S[Active and valid]
    S --> P[Attached policy versions]
    P --> A[iot:Connect decision]
    A -->|allow| B[MQTT session]
    A -->|deny| R[Not authorized response]

References: src/…/IotService.java• L516-675 src/…/IotMqttBrokerService.java• L462-499 src/…/IotMqttBrokerService.java• L667-708

Custom authorization

Authorizer state

An IoT custom authorizer is a named resource that points to a Lambda function and defines how a connection token is checked. It has ACTIVE or INACTIVE state. It can use token-signing keys or allow unsigned requests. The control APIs manage its lifecycle, tags, and the account's default-authorizer marker.

An authorizer cannot be deleted while active. The default marker is separate from resource status and also prevents deletion until it is cleared or moved. The default authorizer is represented in resource state. A direct plaintext MQTT connection without a named authorizer does not use it, while a WebSocket upgrade without a named authorizer can use it when the upgrade does not carry an apparent SigV4 signature.

References: src/…/IotAuthorizerService.java• L32-59 src/…/IotAuthorizerService.java• L61-105 src/…/IotAuthorizerService.java• L160-223 src/…/IotAuthorizer.java• L9-23 src/…/IotMqttBrokerService.java• L462-499

Authorization flow

When a client names an authorizer, the service extracts the name from the MQTT username, the WebSocket URL query, or the WebSocket upgrade header. A WebSocket upgrade with no named authorizer uses the default authorizer unless its query appears to contain a SigV4 signature; that signature is not verified. A signed authorizer verifies the token against its configured public keys. The service then invokes the Lambda function with connection data and checks the returned authentication result and policy documents.

The function receives the protocol data that is available on the connection. This can include MQTT credentials, WebSocket headers and query data, the client ID, the server name, and connection metadata. The returned policies first decide iot:Connect for the client ID. The broker then uses those policies for Publish, Subscribe, and Receive checks during that session. Response time values are validated and returned, but they do not schedule later invocation or disconnect work.

The same request and response checks apply to TestInvokeAuthorizer and to a custom authorizer on an MQTT CONNECT.

sequenceDiagram
    participant D as Client
    participant B as MQTT broker
    participant A as Custom authorizer
    participant L as Lambda function
    D->>B: CONNECT with authorizer name and token
    B->>A: Resolve authorizer and verify token
    A->>L: Invoke with connection data
    L-->>A: Authentication result and policies
    A-->>B: iot:Connect decision
    B-->>D: Accept session or reject CONNECT

References: src/…/IotCustomAuthorizer.java• L82-183 src/…/IotCustomAuthorizer.java• L204-297 src/…/IotCustomAuthorizer.java• L303-336 src/…/IotMqttBrokerService.java• L471-539

MQTT connectivity

Broker transports

The embedded MQTT broker accepts plaintext MQTT and MQTT over TLS when enabled. It supports MQTT 3 and MQTT 5 connections with QoS 0 and QoS 1 device flows. The broker can start at service boot or start when an IoT operation needs it.

The broker keeps live sessions and subscriptions in memory. A new connection with the same client ID replaces the old live session. A non-clean session can keep its subscriptions and queued QoS 1 messages for a limited expiry period, and a reconnect resumes them only for the same account, region, and MQTT version. IoT Data connection APIs can inspect or close live sessions and list subscriptions for live or stored sessions.

The plaintext listener is permissive unless the client names a custom authorizer. TLS uses the certificate admission path. MQTT over WebSocket lands on the plaintext listener. It uses the same broker session and publish behavior, but its upgrade metadata can select a named or default custom authorizer.

The TLS listener uses the service's default TLS certificate and requests a client certificate. When the server certificate is reissued, new handshakes use the new key material while handshakes already in progress can finish with the earlier matching key and certificate. A failed certificate reload keeps the prior certificate in service.

References: src/…/IotMqttBrokerService.java• L186-302 src/…/IotMqttBrokerService.java• L418-435 src/…/IotMqttBrokerService.java• L462-708 src/…/ReloadingKeyManager.java• L20-31

Message flow

An ordinary MQTT publish is checked against the session's iot:Publish policy, recorded by the IoT service, and can update retained-message state. It is then delivered to matching live subscriptions when their iot:Receive policy allows it, and it can trigger topic rules. A reserved AWS IoT topic is handled as a service command first. For example, shadow requests produce response topics instead of acting as ordinary application messages. HTTP IoT Data publishes enter the same service-owned publish path.

The service keeps a bounded recent publish record for observation. Rule evaluation uses the message topic, MQTT client ID, owning account, and JSON payload. A rule can filter messages and project a new JSON document for its actions. A message that does not arrive over MQTT has no client ID, which rule SQL exposes as N/A.

Topic-rule actions run in order after the message path continues. If an action fails, later actions still run. When configured, the error action receives a failure document for the failed actions and the original payload. MQTT acknowledgements and subscriber fan-out do not wait for rule actions. A slow action delays later rule evaluation but does not delay the MQTT acknowledgement or normal delivery. During reset or shutdown, queued rule work is skipped. If the rule backlog exceeds its bound, new rule evaluations are skipped rather than applying back pressure to MQTT.

References: src/…/IotMqttBrokerService.java• L751-861 src/…/IotMqttBrokerService.java• L871-961 src/…/IotService.java• L1152-1210 src/…/IotService.java• L1594-1627 src/…/IotService.java• L1797-1834 src/…/RuleSqlContext.java• L3-8 src/…/RuleSqlEvaluator.java• L73-125

MQTT over WebSocket

WebSocket bridge

MQTT over WebSocket is available at /mqtt on the HTTP and HTTPS listeners. The bridge accepts binary WebSocket frames and pipes their MQTT bytes to the plaintext broker listener. Broker sessions, subscriptions, publish behavior, and custom-authorizer checks therefore remain the same as for direct plaintext MQTT.

The bridge does not request a client certificate. It carries upgrade headers, URL query data, server name, and client address into custom-authorizer processing. Floci does not verify a SigV4 WebSocket signature. A WebSocket connection with no named authorizer uses the default authorizer unless the upgrade carries an apparent SigV4 signature. Text frames are not valid MQTT transport data and close the bridge.

flowchart LR
    W[WebSocket upgrade at /mqtt] --> H[Bridge connection data]
    H --> B[Plain MQTT broker session]
    B --> S[Shared sessions and subscriptions]
    B --> P[Shared publish and rule path]

The bridge starts the broker when an upgrade needs it. If the broker is disabled or cannot start, the upgrade receives service-unavailable behavior. A normal HTTP request to /mqtt is not an MQTT session. A future child page can describe wire-level protocol behavior when introduced.

References: src/…/IotMqttWebSocketBridge.java• L21-29 src/…/IotMqttWebSocketBridge.java• L55-113 src/…/IotMqttWebSocketBridge.java• L121-231 src/…/IotMqttBrokerService.java• L462-539

Fleet indexing

Index configuration

Fleet indexing provides a searchable view of things for one account and region. The configuration controls thing and thing-group indexes. Indexing is off until the region receives an update. Managed fields come from the selected modes. Custom fields and filters add optional indexed data.

The service accepts settings for registry, shadow, connectivity, named-shadow, and Device Defender data. The current search path evaluates registry fields, thing attributes, direct group names, and enabled connectivity data. Unsupported indexed domains return an error instead of silently producing empty matches.

References: src/…/IotFleetIndexingService.java• L39-58 src/…/IotFleetIndexingService.java• L119-165 src/…/IotFleetIndexingService.java• L332-373

SearchIndex turns current thing and direct group state into index documents. It adds connectivity state when connectivity indexing is enabled. It applies the configured query language and returns matching things in thing-name order. Queries can match core thing fields, group names, attributes, and enabled connectivity fields with Boolean operators and simple wildcards.

Results use request-bound continuation tokens. A token carries the original search parameters and cursor. The service rejects a token that was edited or reused with different parameters. The query parser rejects unsupported forms and invalid fields instead of returning misleading empty matches.

This diagram shows how indexing configuration controls a search over thing state.

flowchart LR
    C[Indexing configuration] --> I[Enabled thing index]
    T[Things and direct group membership] --> D[Index documents]
    M[Live or last connectivity state] --> D
    Q[Search request] --> V[Query validation]
    I --> V
    D --> M2[Matching things in name order]
    V --> M2
    M2 --> P[Page and continuation token]

The thing-group index can be described when enabled, but searching it is not modeled. Search of the thing index is the supported fleet search path.

References: src/…/IotFleetIndexingController.java• L44-107 src/…/IotFleetIndexingService.java• L167-250 src/…/IotFleetIndexQuery.java• L14-21 src/…/IotFleetIndexQuery.java• L205-234

Endpoint state

Endpoint discovery

DescribeEndpoint returns the address that IoT Data clients use to reach the emulator. By default it reflects the configured base URL authority. An explicit endpoint address can provide a host name or host:port when the deployment exposes AWS-like ports for HTTPS, MQTT over TLS, or WebSocket.

The returned address does not move a broker listener or configure DNS. It must match the network route and certificate names used by the client.

References: src/…/IotController.java• L64-69 src/…/IotService.java• L236-243

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep certificate registration, certificate status, certificate mode, policy attachment, and TLS CONNECT admission aligned. A change in one can silently change which devices can connect.
  • Keep the certificate lookup rule consistent across account partitions. A device certificate must not be admitted under an arbitrary account when more than one registration exists.
  • Keep custom-authorizer parameter extraction consistent across MQTT usernames, WebSocket queries, and upgrade headers. These paths must produce the same Lambda input shape.
  • Keep custom-authorizer response validation aligned between TestInvokeAuthorizer and broker CONNECT. Changes to policy, principal, signature, or time-value checks affect both paths.
  • Keep connection policies aligned with the later MQTT action checks. A policy that admits iot:Connect must still grant the intended Publish, Subscribe, and Receive actions.
  • Keep WebSocket default-authorizer selection aligned with the apparent SigV4 bypass rule. The bridge does not verify the signature before it skips custom-authorizer processing.
  • Keep WebSocket bridge metadata and broker session admission aligned. The bridge uses the broker's plaintext path instead of a second authorization path.
  • Keep persistent-session identity and expiry aligned with account, region, MQTT version, client takeover, queued QoS 1 delivery, and iot:Receive checks on reconnect.
  • Keep domain configuration status, managed endpoint records, authorizer settings, endpoint discovery, and the actual broker listener contract aligned. Domain state does not itself move a listener.
  • Keep V2 logging option setup rules, regional storage, partial-update behavior, and supported log levels aligned between the API and logging consumers.
  • Keep HTTP IoT Data publishes and MQTT publishes on the same retained-message, reserved-topic, publish-record, and rule behavior where the AWS contract is shared.
  • Keep rule context values aligned for MQTT and non-MQTT publishes. The client ID and owning account affect SQL filters and projections.
  • Keep rule admission, queue limits, reset behavior, action failure handling, and broker acknowledgements aligned. Rule overload or an action failure must not change the normal MQTT delivery contract.
  • Keep TLS listener certificate reload behavior aligned with the shared default TLS configuration. New handshakes must use new material while in-progress handshakes retain a matching generation.
  • Keep indexing modes, derived managed fields, index availability, accepted query fields, connectivity documents, and continuation-token parameters aligned.

Important failure modes

TriggerConsequenceGuard
Device certificate is unregistered, inactive, expired, or has no allowed iot:Connect policyTLS MQTT CONNECT is rejectedRegister the certificate, activate it, attach an allow policy, and use the intended client ID
The same device certificate is registered in more than one accountThe TLS connection is refused rather than selected for one accountKeep a certificate registered in one account when it is used for device authentication
A signed custom authorizer receives a missing or invalid token signatureThe authorizer is not invoked and the connection or test call failsSend the configured token and a signature that verifies with a configured key
A custom-authorizer function returns invalid principal, policy, or time dataThe connection or test invocation returns an authorizer errorReturn valid authentication data and policy documents within the supported limits
A connected client lacks iot:Publish, iot:Subscribe, or iot:Receive for the requested topic or filterThe publish is refused, the subscription is denied, or delivery is skippedAttach policies that grant the required action on the matching topic resource
A WebSocket upgrade has no named authorizer and no apparent SigV4 signature, but no default authorizer is configuredThe broker refuses the MQTT connectionConfigure an active default authorizer or name an available authorizer
MQTT over WebSocket uses text framesThe bridge closes the WebSocket instead of forwarding MQTT dataSend MQTT packets as binary frames
Broker is disabled or cannot start when a WebSocket client upgradesThe upgrade returns service-unavailable behaviorEnable the IoT MQTT broker and keep its listener available before using /mqtt
MQTT publish exceeds the payload limit or uses unsupported QoS 2The client is disconnected and the publish is not processedKeep publishes within the supported payload and QoS range
A persistent session reconnects with a different MQTT version or account and regionThe stored session is not resumed, so subscriptions and queued messages are not restoredReconnect with the same client identity, account, region, and MQTT version before the session expires
Rule SQL receives a non-object JSON payload when filtering or projection is neededThe rule does not fireSend a JSON object for rules that use fields or a WHERE clause
A topic-rule action failsLater actions run, but the failed action is reported only to the optional error actionKeep action inputs valid and configure an error action when failure reporting is needed
Rule backlog exceeds its limit or reset/shutdown suspends rule workThe publish completes, but its topic actions do not runKeep rule actions short and account for skipped asynchronous rule work
Fleet indexing is off or the requested index is not enabledIndex description or search returns a resource-not-found errorEnable the matching index for the target region before searching
A search uses unsupported fields, invalid syntax, too many terms, or a mismatched continuation tokenSearch returns an invalid-query or invalid-request errorUse enabled fields and reuse a token with the exact original request
An indexing update enables named-shadow indexing without names or enables dependent modes while thing indexing is offThe indexing configuration is rejectedTurn on the base thing index and provide the required named-shadow filter
The first V2 logging update omits roleArn or defaultLogLevel, or uses an unsupported log levelLogging options are not savedProvide both initial values and use a supported log level
V2 logging options are requested for a region with no setupThe API returns a not-configured errorSet the options before reading them
The default TLS configuration is missing or a certificate reload failsThe TLS MQTT listener does not start, or it keeps serving the previous certificateProvide a valid default TLS key store and inspect reload errors before relying on new server certificates
An enabled domain configuration is deleted or an AWS-managed endpoint configuration is targeted for deletionThe domain configuration delete is rejectedDisable customer-managed configurations first and leave AWS-managed endpoint records in place

Key files

FileWhy to read it
src/…/IotService.javaShared IoT state, certificate checks, policy decisions, publishes, shadows, jobs, and topic rules
src/…/IotController.javaControl-plane resource API surface for things, certificates, policies, groups, jobs, and rules
src/…/IotDataController.javaIoT Data shadow, publish, retained-message, and live connection API surface
src/…/IotLoggingController.javaRegional V2 logging options API surface
src/…/IotLoggingService.javaV2 logging option validation and state behavior
src/…/IotV2LoggingOptions.javaV2 logging option state shape
src/…/IotMqttBrokerService.javaMQTT listeners, TLS device admission, custom-authorizer selection, policy checks, session replacement and resumption, subscriptions, fan-out, connectivity state, and rule handoff
src/…/IotMqttWebSocketBridge.java/mqtt WebSocket transport, upgrade metadata, and bridge lifecycle
src/…/IotAuthorizerController.javaCustom authorizer control and test-invocation API surface
src/…/IotAuthorizerService.javaCustom authorizer state, signing-key validation, tags, and default-authorizer state
src/…/IotCustomAuthorizer.javaCustom-authorizer input extraction, token checks, Lambda invocation, and response checks
src/…/IotDomainConfigurationController.javaDomain configuration API surface
src/…/IotDomainConfigurationService.javaManaged endpoint and customer domain configuration state
src/…/IotCertificate.javaCertificate identity, validity, mode, and key material state
src/…/IotDomainConfiguration.javaDomain configuration state and endpoint authentication options
src/…/ReloadingKeyManager.javaTLS server certificate replacement without breaking handshakes already in progress
src/…/IotFleetIndexingService.javaFleet index configuration, document creation, connectivity data, search, and pagination
src/…/IotFleetIndexQuery.javaFleet query language and the fields that search can evaluate
src/…/IotFleetIndexingController.javaFleet indexing and search API surface
src/…/RuleSqlContext.javaContext values that topic-rule SQL can read from a publish
src/…/RuleSqlEvaluator.javaTopic-rule filtering, value conversion, and projection behavior
src/…/IotPublishEventRecorder.javaBounded recent publish record used by the IoT service