Managed Workflows for Apache Airflow
Floci provides an AWS-compatible control plane for managed Apache Airflow environments. Each environment combines durable control-plane state with a private Airflow runtime in real mode, so environment status, runtime health, web access, and S3-backed workflow content work as one service.
The service follows the same container-backed lifecycle model as the other orchestration services. See container orchestration for the shared runtime model and service configuration and lifecycle for emulator-wide lifecycle behavior.
System role
The MWAA system connects environment APIs to an Airflow runtime. MwaaService owns environment records and control-plane behavior. MwaaEnvironmentManager supplies the database and Airflow runtime that make a real environment usable.
| Component | Role |
|---|---|
MwaaController | AWS-compatible REST-JSON entry point for environment requests |
MwaaService | Environment state, validation, tags, access tokens, persistence, and background coordination |
MwaaEnvironmentManager | Runtime creation, health checks, startup setup, content updates, CLI execution, and cleanup |
MwaaProxyManager and MwaaWebProxy | Per-environment web access and Airflow CLI access |
Environment lifecycle
An environment moves from a stored request to a usable Airflow endpoint. Mock mode records the environment without starting a runtime. Real mode starts a private metadata database and Airflow service, then exposes the environment only after both core Airflow health checks pass.
The lifecycle joins control-plane state, runtime readiness, proxy access, and workflow content synchronization.
flowchart LR
A[Create environment] --> B[Validate version and options]
B --> C[Start metadata database]
C --> D[Start Airflow runtime]
D --> E[Check database and scheduler health]
E -->|healthy| F[Mark AVAILABLE]
E -->|container exits| G[Mark CREATE_FAILED]
E -->|startup error| H[Mark CREATE_FAILED and clean up]
F --> I[Expose web and CLI access]
I --> J[Sync DAGs and requirements from S3]
Environment creation
MwaaService validates the environment name, supported Airflow version, and configuration options before it stores the environment as CREATING. In real mode, it fetches the optional startup script, starts the database and Airflow runtime, allocates a proxy port, and creates the environment proxy. If any part fails, the service removes the partial runtime and proxy and releases the port.
References: src/…/MwaaService.java• L112-190 src/…/MwaaService.java• L193-217
Runtime readiness
MwaaEnvironmentManager starts the metadata database before Airflow and waits for the database to accept TCP connections. The environment becomes AVAILABLE only when the Airflow health endpoint reports a healthy metadatabase and scheduler. If either backing container stops before readiness, the service records CREATE_FAILED instead of waiting without end.
References: src/…/MwaaEnvironmentManager.java• L96-140 src/…/MwaaEnvironmentManager.java• L250-314 src/…/MwaaService.java• L484-527
Environment deletion
Deletion changes the record to DELETING, stops the environment proxy, removes the Airflow and database runtime, releases the runtime volumes and proxy port, and then removes the stored record. Shutdown uses the same cleanup path unless configuration tells Floci to leave the runtime running.
References: src/…/MwaaService.java• L100-109 src/…/MwaaService.java• L308-324 src/…/MwaaEnvironmentManager.java• L331-345
Airflow runtime
Real mode gives each environment its own metadata database and Airflow service. The database is private to the Airflow service, while Floci reaches the Airflow webserver through the environment proxy. The runtime uses a host port when Floci runs outside Docker and the container port when Floci runs inside Docker.
Runtime startup
The runtime applies setup in a fixed order so readiness reflects a usable Airflow service. It runs the optional startup script, restores Floci-managed settings, migrates the metadata database, creates the administrator, starts the scheduler, and then starts the webserver. The startup script runs in the same shell as these later steps, so its intended environment setup is available to Airflow. A failing script or migration prevents the runtime from becoming ready.
References: src/…/MwaaEnvironmentManager.java• L146-248 src/…/MwaaEnvironmentManager.java• L593-636
Runtime configuration
Creation selects an Airflow version from the configured supported versions and sets the database, executor, security, administrator, and Floci endpoint settings. AirflowConfigurationOptions accepts AWS-style section.key settings and maps them to Airflow settings at runtime. Floci keeps the settings that its runtime and AWS-compatible access need under its control.
The runtime also matches each Airflow version with the Python version used by the corresponding MWAA image family. This keeps package installation compatible with the selected Airflow release.
References: src/…/MwaaService.java• L126-154 src/…/MwaaService.java• L351-400 src/…/MwaaEnvironmentManager.java• L156-175 src/…/MwaaEnvironmentManager.java• L518-563
Startup configuration
StartupScriptS3Path identifies a script in the environment source bucket. The script runs during runtime creation and can prepare the Airflow environment before migration and service start. Floci restores its reserved runtime and AWS endpoint settings after the script, so user setup cannot redirect Airflow or its workflow code away from the emulator.
A configured script is injected before the container starts. A missing bucket, unreadable script, failed injection, or script failure blocks creation. Changes to the startup-script path are not applied to a live runtime; the environment must be recreated.
References: src/…/MwaaService.java• L167-185 src/…/MwaaService.java• L623-633 src/…/MwaaEnvironmentManager.java• L200-233 src/…/MwaaEnvironmentManager.java• L593-635
Workflow content
Workflow content remains linked to Floci's S3 service after the environment becomes available. Background synchronization updates the running Airflow workspace without rebuilding the environment.
DAG synchronization
The DAG sync pass lists the configured S3 prefix and copies changed files into the Airflow workspace. It also removes files that no longer exist in S3. A read or copy error affects that sync pass only and does not make the environment unavailable.
References: src/…/MwaaService.java• L529-594 src/…/MwaaEnvironmentManager.java• L347-360
Requirements installation
When enabled, the sync pass watches the configured requirements object by ETag. A changed file is installed in the running Airflow service. Installation errors are warnings and do not change the environment state.
References: src/…/MwaaService.java• L596-615 src/…/MwaaEnvironmentManager.java• L362-380
Control-plane operations
The control plane presents environment state and access operations through the AWS-compatible MWAA surface. It stores records by account and region, so the same environment name can exist in separate scopes. Tags belong to the environment record and are also available through resource ARN operations.
Environment updates
Updates change control-plane fields such as source locations, access settings, logging settings, and sizing metadata. Airflow version, Airflow configuration options, requirements path, and startup-script path are creation-time concerns in this runtime model. Requests that need a new Airflow runtime are rejected instead of being reported as applied.
References: src/…/MwaaService.java• L241-305
Web and CLI access
The environment URL points to a per-environment proxy. The proxy forwards normal web requests to Airflow. It treats POST /aws_mwaa/cli as a control path, validates the environment token, and runs an allowed Airflow CLI command in the matching runtime.
The CLI bridge accepts a defined set of MWAA commands and runs them without a shell. This preserves argument boundaries and prevents shell operators from becoming executable commands. It returns output in the AWS-compatible response shape while keeping slow runtime commands off the HTTP event loop.
sequenceDiagram
participant Client
participant Proxy as MWAA web proxy
participant Airflow as Airflow webserver
participant Runtime as Airflow runtime
Client->>Proxy: Web request
alt CLI request
Client->>Proxy: POST /aws_mwaa/cli with bearer token
Proxy->>Proxy: Validate environment token
Proxy->>Runtime: Run allowed Airflow CLI command
Runtime-->>Proxy: stdout and stderr
Proxy-->>Client: Encoded CLI response
else Airflow web request
Proxy->>Airflow: Forward request
Airflow-->>Proxy: Airflow response
Proxy-->>Client: Forward response
end
References: src/…/MwaaService.java• L327-349 src/…/MwaaEnvironmentManager.java• L383-408 src/…/MwaaWebProxy.java• L22-32 src/…/MwaaWebProxy.java• L104-170
State persistence
Environment records survive process restarts through the MWAA storage backend. Runtime containers are not automatically reconnected to those records. In real mode, the readiness and DAG sync workers start with the service and act on stored environments. Shutdown cleanup can be disabled when another process must keep the containers alive.
References: src/…/MwaaService.java• L57-109 src/…/MwaaService.java• L640-730
Change checklist
When these files or sections are changed, remember to consider these:
- If
Environmentor either environment request shape changes, check that update rules still match what a live Airflow runtime can change without recreation. - If runtime identity or endpoint rules change, verify that the proxy, token lookup, Docker resource names, and account-region scope still select the same environment.
- If startup-script handling changes, preserve Floci-managed Airflow, security, and AWS endpoint settings that workflow code needs to reach the emulator.
- If startup order or health criteria changes, keep status transitions aligned with the point at which Airflow can accept workflow work.
- If S3 path or ETag handling changes, check both DAG deletion and requirements re-install behavior because both use background synchronization.
- If Airflow option validation or mapping changes, keep the accepted AWS
section.keyform aligned with the runtime settings and protected settings. - If create or delete rollback changes, keep proxies, ports, containers, and volumes balanced across every partial-provisioning path.
- If proxy routing or CLI execution changes, preserve the split between forwarded Airflow requests and authenticated allowed-command execution.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Startup script is missing, unreadable, fails, or cannot be injected | Creation ends in CREATE_FAILED and the partial runtime is removed | Startup setup is fetched before runtime creation, injected before start, and a configured script failure is fatal |
| An Airflow version is malformed or not supported | Creation is rejected before runtime resources are created | The service validates the version shape and configured supported-version list |
| An update changes Airflow version, Airflow options, requirements path, or startup-script path | The request is rejected instead of changing a live runtime | Recreate the environment for runtime-level changes |
| Airflow metadata database or scheduler is not healthy | The environment stays in CREATING | Availability requires both health sections to report healthy |
| Postgres or Airflow exits before readiness | The environment changes to CREATE_FAILED instead of waiting without end | The readiness pass checks container state and the Airflow health endpoint |
| A DAG object cannot be read or copied | That DAG is skipped for the sync pass | Sync errors are isolated from environment state |
| A CLI token is missing or invalid | The CLI request returns 401 and does not run in Airflow | The proxy validates the bearer token for the target environment |
| The Airflow webserver cannot be reached through the proxy | A normal request returns a gateway or service error | The proxy reports backend connection and response-body failures |
| Floci restarts while environments exist | Stored records have no automatic runtime reconnection | Recreate or otherwise manage the runtime before using the record |
Key files
| File | Why to read it |
|---|---|
| src/…/MwaaController.java | AWS-compatible HTTP entry point |
| src/…/MwaaService.java | Environment CRUD, state transitions, persistence, validation, tokens, rollback, and background synchronization |
| src/…/MwaaEnvironmentManager.java | Database and Airflow lifecycle, readiness, startup setup, protected runtime configuration, workflow content updates, CLI execution, and cleanup |
| src/…/MwaaProxyManager.java, src/…/MwaaWebProxy.java | Per-environment HTTP proxy and CLI bridge |
| src/…/Environment.java, src/…/CreateEnvironmentRequest.java, src/…/UpdateEnvironmentRequest.java, src/…/EnvironmentStatus.java | Environment state and request shapes |