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 / service-config-and-lifecycle

Service configuration and lifecycle

Floci is a local AWS emulator whose shared configuration controls its endpoint, service behavior, storage, network access, compatibility, and TLS. Its lifecycle prepares these settings, validates startup conditions, restores shared state, exposes readiness and operator information, and later cleans up live resources before storage closes.

Startup and shutdown

Startup has an early configuration stage and a later lifecycle stage. Configuration sources prepare the listener and TLS before Quarkus starts the HTTP server. Startup observers then reject invalid service values, while the main lifecycle restores state, starts shared runtimes, runs hooks, and marks the emulator ready.

Shutdown keeps operator hooks and resource cleanup in a defined order. It runs stop hooks, flushes state, and then stops tracked runtimes and storage so cleanup data is not lost.

The main lifecycle relationship is shown below.

sequenceDiagram
    participant C as Configuration
    participant H as HTTP server
    participant L as Emulator lifecycle
    participant R as Stored state and runtimes

    C->>H: Prepare listener and TLS settings
    H->>L: Startup event
    L->>L: Run startup checks and BOOT hooks
    L->>R: Validate, load, and recover state
    L->>R: Restore pollers and shared runtimes
    H->>L: HTTP start event
    L->>L: Run START and READY hooks
    L-->>H: Mark emulator ready
    H->>L: Shutdown events
    L->>L: Run STOP hooks
    L->>R: Flush state
    L->>R: Stop runtimes and storage

References: src/…/EmulatorLifecycle.java• L203-332 src/…/EmulatorLifecycle.java• L349-417 src/…/BedrockRuntimeStartupValidator.java• L18-27 src/…/ServiceQuotasStartupValidator.java• L18-27

Runtime configuration

EmulatorConfig is the shared configuration view for the emulator. It connects the public URL and AWS defaults with service enablement, storage, network and security rules, authentication, protocols, initialization hooks, Docker use, compatibility settings, and TLS.

The effective base URL uses the configured host and transport. A configured hostname replaces the host in returned service URLs. TLS changes the scheme to HTTPS. This keeps URLs usable in local multi-container setups and lets endpoint generation follow the active security mode.

The main configuration groups are:

GroupPurpose
Endpoint and AWS defaultsDefines the public port, returned host, base URL, region, account, and partition.
Persistent stateSelects storage mode, state paths, service flush behavior, and shared-volume behavior.
ServicesEnables APIs and selects mock or live local runtimes.
Network and securityControls DNS behavior, CORS, listener exposure, and network helpers.
Protocols and authenticationSets request limits, protocol checks, and signature validation.
Hooks and TLSSets lifecycle scripts, time limits, HTTPS certificates, and the AWS-style HTTPS port.
CompatibilityAccepts selected LocalStack environment settings when explicit Floci settings are absent.
Shared Docker runtimeDefines the daemon, connection pools, image and credential sources, resource namespace, and log limits for child runtimes.

Storage can use a shared mode and path while still allowing service-specific storage behavior and flush timing. This lets state durability match the needs of each local service. See storage backend for the state model and storage flow.

Protocol settings define the request boundary before service routing. They include body-size limits and checks for wire-protocol claims and signing scopes. See request routing and protocols for how requests move from the shared endpoint to a service.

Network exposure is guarded by default. A listener outside loopback requires explicit approval, and DNS settings can add local suffixes, provide fallback resolvers to spawned containers, or route AWS endpoint names to Floci. Partition selection can come from an explicit partition or the default region. Strict partition mode rejects services that AWS does not publish in the selected partition.

The LocalStack compatibility layer maps supported environment variables into this configuration while keeping explicit Floci and Quarkus values higher priority. Host-native runs also receive safe defaults for their data path and Docker resource namespace. These defaults prevent separate local instances from silently sharing state or child resources.

TLS configuration can also name extra CA certificates for Floci's own outbound HTTPS clients. This trust input applies whether server TLS is enabled, but it is not added to the trust bundle given to launched workloads.

References: src/…/EmulatorConfig.java• L12-127 src/…/EmulatorConfig.java• L178-305 src/…/EmulatorConfig.java• L282-306 src/…/EmulatorConfig.java• L3905-4100 src/…/HostDefaultsConfigSource.java• L8-74 src/…/LocalStackParity.java• L15-24 src/…/LocalStackParity.java• L98-163 src/…/LocalStackParityConfigSource.java• L8-55 src/…/HostDataDir.java• L11-53

Startup validation

Startup validators turn configuration mistakes into early failures instead of delayed request errors. The Bedrock Runtime proxy requires a positive error-body timeout, Service Quotas requires a nonnegative standard on-demand vCPU value, and a configured extra CA file must be readable and contain at least one certificate.

The extra CA check runs even when server TLS is off because the file affects Floci's outbound HTTPS trust. Private keys in the file are ignored; only certificate entries matter.

References: src/…/BedrockRuntimeStartupValidator.java• L18-27 src/…/ServiceQuotasStartupValidator.java• L18-27 src/…/TlsExtraCaStartupValidator.java• L15-55 src/…/EmulatorConfig.java• L4017-4022

TLS setup

TLS setup runs as a configuration source before Quarkus creates its HTTP server. This early step selects certificate material, creates the container trust bundle, and gives the server its internal HTTP and HTTPS listeners.

When TLS is enabled, Floci accepts a readable certificate and key pair or creates a persistent local certificate authority and server certificate. It serves HTTP and HTTPS together through the public endpoint. An optional AWS-style HTTPS listener supports clients that assume port 443. The extra listener defaults to 443, can be disabled with 0, and is not needed when it equals the public port. A configured public-port bind is required. Failure to bind the optional listener is non-fatal.

An extra CA file is a separate trust setting for Floci's outbound HTTPS. Startup rejects a missing, unreadable, or certificate-free file instead of waiting for the first outbound handshake. The extra CA is not copied into the container trust bundle.

The TLS bootstrap follows this path:

  1. Read TLS and storage settings.
  2. Validate the optional outbound extra CA file when one is configured.
  3. Use the supplied certificate and key when both are present and readable.
  4. Otherwise load or create the persistent local CA when self-signed mode is enabled.
  5. Reuse or regenerate the server certificate when its names, issuer, identifiers, or validity are no longer correct.
  6. Write the container trust bundle and Java trust store.
  7. Configure the internal HTTP and HTTPS listeners and the public protocol-detecting proxy.

The public proxy uses the first byte of a connection to select the internal HTTP or HTTPS listener. A TLS handshake starts with byte 0x16; other traffic goes to the HTTP listener. The same rule applies on the optional AWS-style HTTPS port, so clients can use either protocol on a shared public port.

References: src/…/TlsConfigSource.java• L27-48 src/…/TlsConfigSource.java• L103-169 src/…/EmulatorConfig.java• L4006-4048 src/…/TlsProxyServer.java• L24-51 src/…/TlsProxyServer.java• L106-182 src/…/TlsProxyServer.java• L184-231 src/…/TlsExtraCaStartupValidator.java• L34-55

Certificate authority

The local CA is the stable trust anchor for Floci-managed certificates. It persists under the TLS directory so clients can trust one CA across restarts. Floci also uses it for the managed server certificate, ACM certificates, and client certificates used by services such as IoT.

Startup checks the CA certificate and key as a usable matching CA pair. If the pair is corrupt, expired, or mismatched, Floci creates a new one and logs that clients must trust the new certificate. Older CA certificates may be reissued with the same key when they lack required identifiers, but the changed certificate still needs to be imported again.

References: src/…/FlociCertificateAuthority.java• L45-53 src/…/FlociCertificateAuthority.java• L83-135 src/…/FlociCertificateAuthority.java• L172-207

Container trust bundle

The container trust bundle gives launched workloads one trust file for public HTTPS sites and Floci HTTPS sites. It combines the JVM public roots with the Floci trust anchor and removes private-key data from combined certificate inputs.

Docker and Kubernetes launch paths mount the bundle at /etc/floci-ca-bundle.pem. They add standard certificate environment variables only when the workload did not set them, so an explicit workload choice remains in control. Java workloads also receive an adjacent PKCS12 trust store and a Java option that points to it when no later workload setting replaces that option. The bundle and trust store are replaced atomically. If either cannot be written, Floci continues to run, but new workloads may not trust Floci HTTPS until a later boot creates them.

The optional extra CA file is intentionally excluded from this bundle. It changes trust for Floci's own outbound clients only, so private or corporate trust material is not passed to launched workloads.

References: src/…/ContainerCaBundle.java• L32-47 src/…/ContainerCaBundle.java• L60-80 src/…/ContainerCaBundle.java• L88-134 src/…/ContainerCaBundle.java• L140-168 src/…/ContainerCaBundle.java• L183-235 src/…/ContainerCaBundle.java• L237-305 src/…/TlsConfigSource.java• L419-434

Runtime certificate names

The managed certificate can grow when a service creates a local custom hostname. TlsCertificateManager accepts valid names under configured or built-in local suffixes, reissues the leaf with the same key and CA, and reloads the active listener without a restart. This makes a custom API Gateway, IoT, or Cognito hostname usable in the same call.

The certificate manager can also report whether the active certificate covers a hostname. It checks either the managed certificate or a user-provided certificate, including one-label wildcard names, so a caller can distinguish a usable HTTPS name from a name that only resolves to Floci.

Configured names remain separate from names learned during service use. A lifecycle reset removes learned names but keeps configured names. User-provided certificates are not changed, and invalid names do not make the service operation fail.

References: src/…/TlsCertificateManager.java• L33-47 src/…/TlsCertificateManager.java• L88-145 src/…/TlsCertificateManager.java• L147-175 src/…/TlsCertificateManager.java• L199-258

Endpoint name coverage

The server certificate covers default local endpoints and hostnames from the base URL, configured hostname, and IoT endpoint address. When AWS endpoint DNS spoofing is enabled, certificate names also cover the AWS partition and regional endpoint forms that DNS sends to Floci. Learned hostnames survive later boot-time certificate regeneration so a restart does not silently remove a name already used by a client.

DNS routing and certificate names must use the same settings. A hostname can resolve to Floci and still fail at the TLS handshake when the certificate does not cover it.

References: src/…/TlsConfigSource.java• L69-85 src/…/TlsConfigSource.java• L232-340 src/…/TlsConfigSource.java• L459-515 src/…/EmulatorConfig.java• L178-246

Initialization hooks

Initialization hooks are operator scripts tied to the BOOT, START, READY, and STOP lifecycle phases. Floci reads both its native hook tree and the LocalStack-compatible tree, then runs each phase with the configured shell and time limits. The hook configuration also sets the shutdown grace period used by the service runtime.

Startup-phase failures stop the emulator before it becomes ready. Stop-hook failures are logged while cleanup continues. Hook results become lifecycle state that operators can inspect through the initialization information endpoint.

References: src/…/EmulatorConfig.java• L3905-3922 src/…/InitializationHook.java• L1-80 src/…/InitializationHooksRunner.java• L67-157 src/…/EmulatorLifecycle.java• L215-224 src/…/EmulatorLifecycle.java• L294-332

Health and information endpoints

Health endpoints expose process availability and emulator state. The basic health path supports simple checks, while Floci-specific paths show service status, version data, lifecycle progress, hook results, trust material, and reset controls.

Endpoint groupPurpose
/healthBasic process health.
/_floci/health and compatibility health pathsService and version state.
/_floci/infoEmulator information for clients and operators.
/_floci/initLifecycle phases and hook results.
/_floci/ca.pemPublic trust certificate for Floci-managed TLS.
/_floci/state/reset and /state/nukeFull in-process reset of tracked runtimes and stored state.

Reset is a whole-emulator operation. It stops tracked containers, lets resettable services prepare, clears stored state, rebuilds initial service state, and completes reset work in reverse service order.

References: src/…/HealthController.java• L1-80 src/…/EmulatorInfoController.java• L32-201

UI sidecar

The UI is on-demand infrastructure rather than part of normal emulator boot. A request to /ui starts the sidecar in the background and returns a page that checks /ui/status until the sidecar is ready.

The status response reports readiness, the published UI URL, or an error. The redirect uses the request host with the sidecar port, so the same flow works through local hosts and container network names.

References: src/…/UiController.java• L1-180

Shared infrastructure lifecycle

Some services have stored records and live local processes or containers. Lifecycle management treats them as one resource so startup can recover live state and shutdown can stop the runtime before final storage cleanup.

The shared lifecycle covers these resource types:

  • Event-source pollers and background workers.
  • Database, cache, broker, registry, and Flink runtimes.
  • Lambda, ECS, and other process-bound workloads.
  • The UI sidecar and tracked child containers.

Services may use mock mode when no live runtime is needed. Services that use external runtimes can reconcile resources left on Docker after an interrupted run. Container-based services also receive the boot-created trust bundle when TLS is enabled, so their runtimes can call Floci over HTTPS. Shared Docker settings define the daemon, control and streaming connection pools, request timeouts, image and credential sources, resource namespace, log limits, and labels for these runtimes.

See container orchestration for the service-facing container lifecycle.

References: src/…/EmulatorLifecycle.java• L220-417 src/…/EmulatorConfig.java• L749-889 src/…/EmulatorConfig.java• L3971-4100 src/…/ContainerCaBundle.java• L140-235

Change checklist

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

  • Keep TLS directory selection, CA loading, server certificate generation, container bundle creation, Java trust store creation, and the CA endpoint on the same trust chain.
  • Keep user certificate rules and self-signed fallback aligned. A partial certificate pair must fail clearly instead of selecting an unintended trust model.
  • Keep extra CA validation aligned with outbound trust assembly. The configured file must be checked at startup, while its certificates must remain out of the workload bundle.
  • Keep DNS spoofing names and certificate SAN generation aligned for every endpoint form that Floci intercepts.
  • Keep the public port, internal TLS ports, optional AWS HTTPS port, and proxy bind state aligned. An optional bind failure must not reserve a port that is not serving traffic.
  • Keep the container bundle mount path, Java trust store path, and non-overriding environment behavior aligned with Docker and Kubernetes launchers.
  • When a startup validator or hook phase changes, keep its lifecycle call site and reported state aligned.
  • Preserve shutdown ordering: stop hooks, flush state, stop live runtimes, then close storage.
  • When compatibility mappings change, preserve explicit Floci and Quarkus settings as higher-priority overrides.
  • When a live runtime is added, connect its configuration to restoration, readiness, reset, and shutdown cleanup.
  • When Docker pool, timeout, namespace, or label settings change, keep all child runtime managers on the same daemon and resource scope.
  • When host, TLS, DNS, or endpoint defaults change, keep returned service URLs and child-runtime network access consistent.
  • When an endpoint advertises a custom HTTPS hostname, keep its certificate coverage check aligned with the active certificate source.

Important failure modes

TriggerConsequenceGuard
TLS is enabled with no readable certificate pair and self-signed mode is offStartup fails before the server is readyProvide both certificate paths or enable self-signed TLS
floci.tls.extra-ca-path names a missing, unreadable, or certificate-free fileStartup fails before outbound HTTPS calls beginPoint the setting to a readable PEM file with at least one certificate
The persistent CA is replaced or regeneratedClients that trust the old CA reject new Floci certificatesKeep the TLS directory and re-import the CA after an intentional change
The container trust bundle or Java trust store cannot be writtenNew workloads may reject Floci HTTPSCheck the boot warning and make the TLS directory writable
The optional AWS HTTPS port cannot bindClients that assume port 443 cannot connect, but the main endpoint can still workUse a free port or set the extra port to 0; use the proxy's actual bind state for port ownership
AWS DNS spoofing is enabled without matching certificate namesClients reach Floci by DNS but fail during the TLS handshakeGenerate the certificate from the same DNS and partition settings
A custom HTTPS hostname is not covered by the active certificateA client can resolve Floci but rejects the TLS handshakeUse a managed local name or provide a certificate whose names cover the endpoint
A startup hook or validator failsThe emulator does not become readyFix the script or invalid value and review the startup log
A stop hook failsHook work may remain, but resource cleanup continuesMake stop hooks safe to retry and inspect shutdown output
The trust bundle is missing when a workload startsThe workload cannot trust Floci HTTPS or a Floci-issued issuerRestore bundle creation before launching new workloads
Reset clears storage while a tracked runtime remains activeA live workload can continue without matching stored stateStop tracked runtimes before the storage wipe
Strict partition mode sees a service that is absent from the selected partitionThe request is rejected even though the local service is enabledCheck partition service rules or disable strict mode when local cross-partition behavior is intended
A native binary runs without an explicit data path and its default changesThe process can start with a new empty state directoryPreserve the platform data directory or set the persistent path explicitly
The listener binds outside loopback without explicit approvalThe emulator exposes its APIs to reachable networksKeep the listener on loopback or enable unsafe network exposure deliberately
A shared Docker connection pool is exhausted by long-lived runtimesNew container operations wait or fail while live runtimes remain activeSize the control and streaming pools for the expected workload and set finite request timeouts
TLS proxy backend detection receives a TLS ClientHello on a service that starts TLS directlyThe connection is sent to the HTTPS backend instead of being treated as plaintextKeep the shared TLS handshake marker aligned with protocol endpoints that accept direct TLS

Key files

FileWhy to read it
src/…/EmulatorConfig.javaDefines the shared endpoint, service, storage, network, hook, compatibility, Docker, and TLS settings.
src/…/HostDefaultsConfigSource.javaSupplies safe host-native state and Docker namespace defaults.
src/…/HostDataDir.javaSelects the default persistent data directory for host-native runs.
src/…/FlociVersion.javaDefines the version used by health responses and certificate metadata.
src/…/LocalStackParity.javaTranslates supported LocalStack environment settings into Floci behavior.
src/…/TlsConfigSource.javaPrepares certificates, trust material, and server listener settings before HTTP startup.
src/…/TlsProxyServer.javaShares the public port between HTTP and HTTPS and manages the optional AWS-style HTTPS port.
src/…/FlociCertificateAuthority.javaLoads or creates the persistent local trust anchor and issues Floci certificates.
src/…/ContainerCaBundle.javaCreates the PEM and Java trust material used by launched workloads and assembles outbound trust.
src/…/TlsExtraCaStartupValidator.javaRejects invalid extra CA configuration before the emulator starts serving.
src/…/TlsCertificateManager.javaAdds allowed runtime hostnames, checks active certificate coverage, and reloads the managed certificate.
src/…/BedrockRuntimeStartupValidator.javaEnforces the Bedrock proxy timeout contract at startup.
src/…/ServiceQuotasStartupValidator.javaEnforces the Service Quotas vCPU contract at startup.
src/…/EmulatorLifecycle.javaCoordinates startup, recovery, readiness, reset, resource cleanup, and shutdown.
src/…/InitializationHooksRunner.javaRuns lifecycle hooks and records their results.
src/…/HealthController.javaExposes basic health state.
src/…/EmulatorInfoController.javaExposes lifecycle, trust, service, and reset information.
src/…/UiController.javaStarts and reports the on-demand UI sidecar.