Files
floci/docs/services/kinesisanalytics.md
T
Priamo Germosen d78520d5cb feat(kinesisanalytics): add Managed Service for Apache Flink (Kinesis Analytics V2) (#1914)
* feat(kinesisanalytics): add Managed Service for Apache Flink (Kinesis Analytics V2)

Adds the kinesisanalyticsv2 service (X-Amz-Target KinesisAnalytics_20180523.*):
a control-plane state machine plus a real Apache Flink JobManager container spun up
as a sidecar on StartApplication, modeled on the AmazonMQ->RabbitMQ pattern.

- CreateApplication -> READY, StartApplication -> STARTING -> RUNNING via a readiness
  poller, StopApplication -> READY, DeleteApplication -> removed
- Container image chosen from the requested RuntimeEnvironment (FLINK-1_15..1_20 ->
  apache/flink:1.x) via KinesisAnalyticsRuntimes, with an optional operator override;
  unsupported runtimes (SQL / Zeppelin) rejected with InvalidArgumentException
- Container naming via ContainerStorageHelper.resourceName (floci-kinesisanalytics-<name>)
- Registered in ResolvedServiceCatalog, dispatched by AwsJson11Controller; container
  teardown wired into EmulatorLifecycle.onStop
- Tests: service + handler unit tests, @QuarkusTest integration, Java SDK compatibility test
- Docs: service page, services index, README, environment-variable reference

* fix(kinesisanalytics): enforce delete/update state and version/timestamp guards

Addresses review feedback (self-review + Greptile) on the Managed Flink service:

- DeleteApplication rejects a non-READY (RUNNING/STARTING) application with
  ResourceInUseException; the caller must StopApplication first (Greptile P1)
- DeleteApplication validates the required CreateTimestamp against the stored value
- UpdateApplication validates CurrentApplicationVersionId (ConcurrentModificationException
  on mismatch, InvalidArgumentException when absent)
- StopApplication error message reads 'RUNNING or STARTING' to match the guard
- Readiness poller @PreDestroy awaits termination (bounded) before returning so a
  mid-flight write cannot race the shutdown storage flush
- Drop the unused Tags field from FlinkApplication (full tag support tracked as a follow-up)
- Compat test @AfterAll logs tolerated teardown failures (AGENTS.md) and stops before delete

Tests updated accordingly and verified live against the packaged jar.

* feat(kinesisanalytics): deploy and run the application JAR on the Flink cluster

Implements real job submission for Managed Service for Apache Flink, so the AWS
'deploy a JAR' flow actually runs the job (previously only a bare JobManager reached RUNNING):

- CreateApplication parses and stores ApplicationConfiguration (ApplicationCodeConfiguration
  S3ContentLocation + ParallelismConfiguration); DescribeApplication echoes it back as
  ApplicationConfigurationDescription
- StartApplication reads the JAR from Floci's local S3 (via S3Service), starts a JobManager plus a
  TaskManager (sharing the JobManager network namespace for localhost RPC), then uploads and runs the
  JAR via the Flink REST API (new FlinkRestClient); the app reaches RUNNING when the Flink job is RUNNING
- StopApplication cancels the job and tears down both containers
- Applications created without code still come up as a bare cluster
- Docs + README updated; unit tests for config round-trip; verified live end-to-end against the
  packaged jar (S3 JAR -> RUNNING Flink job -> stop/delete cleanup)

Not yet emulated: EnvironmentProperties injection, snapshots/savepoints, in-place code updates.

* fix(kinesisanalytics): align Flink runtimes with AWS and add the 2.x line

The runtime map now mirrors the runtimes AWS Managed Service for Apache Flink actually offers:

- Add FLINK-2_0 / 2_1 / 2_2 / 2_3 -> apache/flink:2.0/2.1/2.2/2.3 (the Flink 2.x line; FLINK-2_2 is in
  the AWS SDK RuntimeEnvironment enum and the whole 2.x line has published apache/flink images)
- Remove FLINK-1_16 / FLINK-1_17 -> AWS does not offer these runtimes, so Floci should reject them too
  rather than accept versions real AWS refuses

Supported set: FLINK-1_15, 1_18, 1_19, 1_20, 2_0, 2_1, 2_2, 2_3. Tests + docs + README updated.

* test(kinesisanalytics): cover both Flink 1.18 and 2.3 in the SDK compat test

Refactor the single-runtime compat test into an abstract ordered lifecycle run against two
runtimes, so the suite guards both the Flink 1.x and 2.x lines (Flink 2.0 changed the config
system and boots slower):

- AbstractKinesisAnalyticsV2LifecycleTest: PER_CLASS instance state + the create->start->RUNNING->
  list->stop->unsupported->delete lifecycle, parameterized on an abstract runtime()
- KinesisAnalyticsV2Flink118Test (FLINK-1_18) and KinesisAnalyticsV2Flink23Test (FLINK-2_3)
- FLINK-2_3 is passed as a string (newer than the pinned SDK 2.44.14 enum) and asserted via
  runtimeEnvironmentAsString(); RUNNING wait bumped to 300s for Flink 2.x's slower boot

Verified live: both subclasses boot real apache/flink:1.18 and :2.3 clusters and reach RUNNING
(0 skipped). CI now exercises two clusters; both skip gracefully when Docker is unavailable.

* fix(kinesisanalytics): preserve AwsException from a bad application-code S3 location

StartApplication's catch(RuntimeException) wrapped every failure from startCluster into
InternalFailureException (HTTP 500) — including the AwsException that readJar throws when the
application-code S3 object is missing/empty/unreadable. A client's bad S3 code location therefore
surfaced as a 500 server error instead of the intended InvalidArgumentException (400).

Now AwsException propagates as-is (preserving its error code and message); only unexpected
RuntimeExceptions (e.g. Docker unavailable) become InternalFailureException. Addresses Greptile P1.

* feat(kinesisanalytics): add resource tagging (TagResource/UntagResource/ListTagsForResource)

Adds Tags support to CreateApplication plus TagResource, UntagResource, and
ListTagsForResource, dispatched as regular JSON1.1 actions under the same
KinesisAnalytics_20180523 target prefix as every other action — verified
against the real botocore kinesisanalyticsv2 model that this API has no
separate REST tagging endpoint (protocol is pure "json"/1.1 with all
operations on POST /), unlike REST-JSON services (EKS, MWAA) that use the
shared /tags/{arn} controller.

Tags is a list of {Key, Value} objects on the wire (not a map), same shape
MemoryDB's handler already uses for its own tagging actions; mirrored that
parse/build pattern rather than the map-shaped TagHandler interface. Tags
are stored on FlinkApplication but, matching the real API, never echoed in
ApplicationDetail (CreateApplication/DescribeApplication) — only
ListTagsForResource returns them. TagResource enforces AWS's 50
user-defined-tag ceiling (TooManyTagsException) on both CreateApplication
and TagResource.

docs/services/kinesisanalytics.md's action table is auto-generated from the
handler source (tools/docs/regen_action_docs.py) — regenerated it and filled
in the three new rows' hand-written descriptions.

* feat(kinesisanalytics): inject EnvironmentProperties into the Flink cluster

CreateApplication now accepts ApplicationConfiguration.EnvironmentProperties
.PropertyGroups and writes them to /etc/flink/application_properties.json in
both the JobManager and TaskManager containers before the job runs — the
same well-known path and JSON shape (a list of {PropertyGroupId, PropertyMap}
objects, matching the AWS API's own PropertyGroups shape) real Managed
Service for Apache Flink uses, so a JAR written against
KinesisAnalyticsRuntime.getApplicationProperties() picks them up unmodified
against Floci. DescribeApplication echoes them back under
ApplicationConfigurationDescription.EnvironmentPropertyDescriptions
.PropertyGroupDescriptions.

/etc/flink does not exist in the stock apache/flink image, and the
container's non-root "flink" user (uid 9999) can't create it directly under
/etc (confirmed live: mkdir -p /etc/flink fails with permission denied as
that user). The fix, also verified live: name the tar entry
"flink/application_properties.json" and extract into the existing /etc
rather than targeting /etc/flink directly — the daemon-level copy API can
create the missing subdirectory as part of unpacking the archive even
though the in-container user couldn't, landing as root:root 775 (so it's
still world-readable by the flink user). A real apache/flink:1.18 container
was used to verify both the failure mode and the fix before writing the
Java implementation.

* feat(kinesisanalytics): add application snapshot (savepoint) support

Adds CreateApplicationSnapshot/DescribeApplicationSnapshot/ListApplicationSnapshots/
DeleteApplicationSnapshot. Triggers a real Flink savepoint of the running job and
polls it to completion the same way StartApplication polls job readiness. Snapshot
files land on a persistent named Docker volume mounted at /opt/flink/savepoints in
the JobManager container, so they survive a Stop/Start cycle; the volume is only
removed on DeleteApplication.

* feat(kinesisanalytics): support in-place application code updates

UpdateApplication with a new ApplicationCodeConfigurationUpdate (or
ParallelismConfigurationUpdate) now redeploys onto an already-running application
without tearing down its JobManager/TaskManager containers: the current job is
cancelled and the new JAR is uploaded and run on the same cluster, transitioning
RUNNING -> STARTING -> RUNNING the same way StartApplication submits a fresh job.
Updating a READY application just stores the new code location for the next
StartApplication. Attaching code to a running bare cluster for the first time is
not yet supported and is rejected with InvalidRequestException.

* fix(kinesisanalytics): use AWS's documented generic InternalFailure code

startApplication and updateApplication's redeploy-code path threw an invented
"InternalFailureException" for unexpected Docker provisioning failures — not a
shape kinesisanalyticsv2's model declares (no operation in this API declares any
5xx shape at all). AWS documents "InternalFailure" (no "Exception" suffix, HTTP
500) as the generic error common to every service's API; it's also already the
default used elsewhere in this codebase (JsonErrorResponseUtils, KMS, Pricing,
SES, CloudControl, EventBridge, and others).

* feat(kinesisanalytics): add CreateApplicationPresignedUrl and SnapshotsEnabled

CreateApplicationPresignedUrl returns a URL to the running application's Flink
Dashboard (UrlType: FLINK_DASHBOARD_URL only; Zeppelin/Studio isn't supported).
Floci has no real session/proxy layer for this, so it returns the JobManager
container's own REST/dashboard URL directly, while still validating UrlType and
SessionExpirationDurationInSeconds against AWS's documented constraints.

ApplicationSnapshotConfiguration.SnapshotsEnabled (default true, matching real
AWS) is now honored on CreateApplication and toggleable via UpdateApplication's
ApplicationSnapshotConfigurationUpdate; CreateApplicationSnapshot rejects the
request with InvalidRequestException while disabled.

* fix(kinesisanalytics): persist flinkJobId as soon as the job is submitted

The readiness poller only called putApplication when advanceToRunning reported
RUNNING, not when it merely assigned flinkJobId after submitting the job (which
returns false until the job state catches up). pendingJars — a separate,
in-process-only cache — is already cleared by that point, so an emulator
restart between job submission and reaching RUNNING would leave the
application stuck: no persisted flinkJobId to resume polling, and no cached
JAR left to resubmit.
2026-08-09 15:01:30 -04:00

11 KiB
Raw Blame History

Managed Service for Apache Flink

Protocol: JSON 1.1 Endpoint: http://localhost:4566/

Floci emulates Amazon Managed Service for Apache Flink (the Kinesis Analytics V2 API). Unlike a pure mock, Floci runs a real Apache Flink cluster as Docker sidecars when an application is started and submits the application's JAR to it, so the application reaches a genuine RUNNING state backed by a live Flink job on Floci's Docker network.

Supported Actions

Action Description
CreateApplication Creates a Flink application in the READY state
CreateApplicationPresignedUrl Returns a URL to the application's Flink Dashboard
DescribeApplication Returns details about an application
ListApplications Lists all applications
StartApplication Starts an application, provisioning a Flink JobManager container
StopApplication Stops a running application and tears down its container
UpdateApplication Updates an application (code, parallelism, execution role) and bumps its version; redeploys code in place on a running job
DeleteApplication Deletes an application
TagResource Assigns one or more tags to an application
UntagResource Removes one or more tags from an application
ListTagsForResource Lists the tags assigned to an application
CreateApplicationSnapshot Triggers a Flink savepoint of the application's running job
DescribeApplicationSnapshot Returns details about an application snapshot
ListApplicationSnapshots Lists the snapshots for an application
DeleteApplicationSnapshot Deletes an application snapshot

How it works

  1. CreateApplication: registers the application in the READY state and stores its ApplicationConfiguration (the S3 location of the Flink JAR and the parallelism). No container is started yet — this mirrors AWS, where a freshly created application is not running.
  2. StartApplication: reads the application JAR from Floci's local S3, launches an apache/flink JobManager container (plus a TaskManager for task slots) on Floci's Docker network, uploads the JAR to the cluster and runs it. The application transitions STARTING → RUNNING once the Flink job itself is RUNNING. An application created without code comes up RUNNING as a bare cluster (no job).
  3. StopApplication: cancels the Flink job, tears down the JobManager and TaskManager, and returns the application to READY.
  4. DeleteApplication: requires the application be stopped (READY); tears down any cluster and removes the application.

Because the Flink containers join Floci's Docker network, the job can reach http://floci:4566 to consume local Kinesis or MSK data streams.

Pass an ApplicationConfiguration with an ApplicationCodeConfiguration pointing at a JAR in Floci's local S3, exactly as with real AWS:

export AWS_ENDPOINT_URL=http://localhost:4566

# 1. Upload your Flink job JAR to (local) S3
aws s3 mb s3://flink-code
aws s3 cp my-flink-app.jar s3://flink-code/app.jar

# 2. Create the application pointing at that JAR
aws kinesisanalyticsv2 create-application \
  --application-name jobdemo --runtime-environment FLINK-1_18 \
  --service-execution-role arn:aws:iam::000000000000:role/x \
  --application-configuration '{
    "ApplicationCodeConfiguration": {
      "CodeContent": { "S3ContentLocation": {
        "BucketARN": "arn:aws:s3:::flink-code", "FileKey": "app.jar" } },
      "CodeContentType": "ZIPFILE" },
    "FlinkApplicationConfiguration": {
      "ParallelismConfiguration": { "ConfigurationType": "CUSTOM", "Parallelism": 1 } }
  }'

# 3. Start it — Floci pulls the JAR, runs it on the cluster, and reaches RUNNING
aws kinesisanalyticsv2 start-application --application-name jobdemo --run-configuration '{}'
aws kinesisanalyticsv2 describe-application --application-name jobdemo  # ApplicationStatus: RUNNING

The job's main class is taken from the JAR's manifest (as in AWS Managed Flink).

Updating application code in place

UpdateApplication with a new ApplicationConfigurationUpdate.ApplicationCodeConfigurationUpdate redeploys a new JAR onto an already-running application without tearing down its JobManager/ TaskManager containers: the current Flink job is cancelled and the new JAR is uploaded and run on the same cluster, exactly the way StartApplication submits a job — the application briefly transitions RUNNING → STARTING → RUNNING while the new job comes up. Calling UpdateApplication on a READY application just stores the new code location for the next StartApplication. FlinkApplicationConfigurationUpdate.ParallelismConfigurationUpdate.ParallelismUpdate is also applied.

aws kinesisanalyticsv2 update-application \
  --application-name jobdemo --current-application-version-id 1 \
  --application-configuration-update '{
    "ApplicationCodeConfigurationUpdate": { "CodeContentUpdate": { "S3ContentLocationUpdate": {
      "BucketARNUpdate": "arn:aws:s3:::flink-code", "FileKeyUpdate": "app-v2.jar" } } } }'

Not yet emulated: attaching code to a bare running cluster (one started without code) via UpdateApplication — stop and start the application instead.

Runtime properties (EnvironmentProperties)

Pass ApplicationConfiguration.EnvironmentProperties.PropertyGroups on CreateApplication to configure your application without recompiling it — exactly as with real AWS. Floci writes them to /etc/flink/application_properties.json inside both the JobManager and TaskManager containers before the job runs, the same well-known path real Managed Service for Apache Flink uses, so a JAR written against KinesisAnalyticsRuntime.getApplicationProperties() picks them up unmodified:

aws kinesisanalyticsv2 create-application \
  --application-name jobdemo --runtime-environment FLINK-1_18 \
  --service-execution-role arn:aws:iam::000000000000:role/x \
  --application-configuration '{
    "ApplicationCodeConfiguration": {
      "CodeContent": { "S3ContentLocation": {
        "BucketARN": "arn:aws:s3:::flink-code", "FileKey": "app.jar" } },
      "CodeContentType": "ZIPFILE" },
    "EnvironmentProperties": {
      "PropertyGroups": [
        { "PropertyGroupId": "ProducerConfigProperties",
          "PropertyMap": { "aws.region": "us-west-2", "flink.stream.initpos": "LATEST" } }
      ] }
  }'

DescribeApplication echoes them back under ApplicationConfigurationDescription.EnvironmentPropertyDescriptions.PropertyGroupDescriptions.

Snapshots (savepoints)

CreateApplicationSnapshot triggers a real Flink savepoint of the application's running job — the application must be RUNNING with a deployed job. The snapshot starts CREATING and transitions to READY (or FAILED) once Flink's savepoint completes, polled the same way StartApplication polls job readiness. Snapshot files land on a named Docker volume mounted at /opt/flink/savepoints in the JobManager container, not the container's ephemeral filesystem, so they survive a StopApplication/StartApplication cycle; the volume itself is only removed on DeleteApplication.

aws kinesisanalyticsv2 create-application-snapshot \
  --application-name jobdemo --snapshot-name before-upgrade

aws kinesisanalyticsv2 describe-application-snapshot \
  --application-name jobdemo --snapshot-name before-upgrade  # SnapshotStatus: CREATING -> READY

aws kinesisanalyticsv2 list-application-snapshots --application-name jobdemo

aws kinesisanalyticsv2 delete-application-snapshot \
  --application-name jobdemo --snapshot-name before-upgrade \
  --snapshot-creation-timestamp <SnapshotCreationTimestamp from describe>

Restoring a job from a snapshot (CreateApplication/UpdateApplication with a RestoreConfiguration pointing at one) is not yet emulated.

Pass ApplicationConfiguration.ApplicationSnapshotConfiguration.SnapshotsEnabled: false on CreateApplication (or ApplicationSnapshotConfigurationUpdate.SnapshotsEnabledUpdate on UpdateApplication) to disable snapshots for an application — real AWS defaults this to true. CreateApplicationSnapshot rejects the request with InvalidRequestException while disabled.

CreateApplicationPresignedUrl (with UrlType: FLINK_DASHBOARD_URL) returns a URL to the running application's Flink Dashboard — the application must be RUNNING:

aws kinesisanalyticsv2 create-application-presigned-url \
  --application-name jobdemo --url-type FLINK_DASHBOARD_URL

Real AWS returns a session-authorized, time-limited URL through its own proxy; Floci has no equivalent session/proxy layer, so it returns the JobManager container's own REST/dashboard URL directly — genuinely live and browsable, but not actually session-scoped or time-limited the way SessionExpirationDurationInSeconds implies (the parameter is still validated to AWS's documented 1800–43200 second range). UrlType: ZEPPELIN_UI_URL is rejected, since Zeppelin/Studio applications aren't supported at all (see below).

Supported runtimes

The RuntimeEnvironment requested on CreateApplication selects the Flink image, so the running container matches the requested version:

RuntimeEnvironment Image
FLINK-2_3 apache/flink:2.3
FLINK-2_2 apache/flink:2.2
FLINK-2_1 apache/flink:2.1
FLINK-2_0 apache/flink:2.0
FLINK-1_20 apache/flink:1.20
FLINK-1_19 apache/flink:1.19
FLINK-1_18 apache/flink:1.18
FLINK-1_15 apache/flink:1.15

The set mirrors the runtimes AWS Managed Service for Apache Flink offers; FLINK-1_16 and FLINK-1_17 are not offered by AWS and are rejected. The SQL (SQL-1_0) and Studio (ZEPPELIN-FLINK-*) runtimes have no plain Flink image and are also rejected with InvalidArgumentException.

Configuration

Variable Default Description
FLOCI_SERVICES_KINESIS_ANALYTICS_ENABLED true Enable or disable the service
FLOCI_SERVICES_KINESIS_ANALYTICS_MOCK false Skip the Flink container; StartApplication comes up RUNNING immediately (useful without a Docker daemon)
FLOCI_SERVICES_KINESIS_ANALYTICS_DEFAULT_IMAGE (unset) Optional override pinning every application to one image regardless of RuntimeEnvironment. When unset, the image is chosen from the runtime (see above)

Example

export AWS_ENDPOINT_URL=http://localhost:4566

# Create an application (lands in READY)
aws kinesisanalyticsv2 create-application \
  --application-name demo \
  --runtime-environment FLINK-1_18 \
  --service-execution-role arn:aws:iam::000000000000:role/x \
  --endpoint-url $AWS_ENDPOINT_URL

# Start it — spins up a real Flink JobManager container (STARTING -> RUNNING)
aws kinesisanalyticsv2 start-application --application-name demo \
  --run-configuration '{}' --endpoint-url $AWS_ENDPOINT_URL

# Check status
aws kinesisanalyticsv2 describe-application --application-name demo --endpoint-url $AWS_ENDPOINT_URL