software.amazon.awssdk
athena
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 3e49bbcf44..c894a2406c 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -39,6 +39,7 @@ import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.kafka.KafkaClient;
import software.amazon.awssdk.services.mq.MqClient;
+import software.amazon.awssdk.services.kinesisanalyticsv2.KinesisAnalyticsV2Client;
import software.amazon.awssdk.services.athena.AthenaClient;
import software.amazon.awssdk.services.athena.model.GetQueryExecutionRequest;
import software.amazon.awssdk.services.athena.model.QueryExecutionState;
@@ -397,6 +398,14 @@ public final class TestFixtures {
.build();
}
+ public static KinesisAnalyticsV2Client kinesisAnalyticsV2Client() {
+ return KinesisAnalyticsV2Client.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ .build();
+ }
+
public static AthenaClient athenaClient() {
return AthenaClient.builder()
.endpointOverride(ENDPOINT)
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AbstractKinesisAnalyticsV2LifecycleTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AbstractKinesisAnalyticsV2LifecycleTest.java
new file mode 100644
index 0000000000..0a4246a42d
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AbstractKinesisAnalyticsV2LifecycleTest.java
@@ -0,0 +1,227 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestMethodOrder;
+import software.amazon.awssdk.services.kinesisanalyticsv2.KinesisAnalyticsV2Client;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.ApplicationDetail;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.ApplicationStatus;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.CreateApplicationRequest;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.CreateApplicationResponse;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.DeleteApplicationRequest;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.DescribeApplicationRequest;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.KinesisAnalyticsV2Exception;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.ListApplicationsRequest;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.RuntimeEnvironment;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.StartApplicationRequest;
+import software.amazon.awssdk.services.kinesisanalyticsv2.model.StopApplicationRequest;
+
+import java.time.Duration;
+import java.time.Instant;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Ordered lifecycle for Managed Service for Apache Flink (Kinesis Analytics V2), exercised against a
+ * specific Flink runtime supplied by {@link #runtime()}. Concrete subclasses pin a runtime so the suite
+ * guards both the Flink 1.x and 2.x lines (Flink 2.0 changed the config system and boots slower):
+ * CreateApplication → READY, StartApplication provisions a real {@code apache/flink} cluster and the
+ * application transitions to RUNNING, ListApplications, StopApplication → READY, unsupported-runtime
+ * rejection, DeleteApplication.
+ *
+ * Uses {@code PER_CLASS} instance lifecycle so each concrete subclass gets its own state (static
+ * fields would collide across subclasses). Requires a running Floci with
+ * {@code kinesis-analytics.mock=false} and a working Docker daemon; when the application never reaches
+ * RUNNING (Docker/Flink unavailable in CI), the dependent assertions skip rather than fail, mirroring
+ * {@code AmazonMqTest} / {@code MskTest}.
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+abstract class AbstractKinesisAnalyticsV2LifecycleTest {
+
+ private static final String ROLE = "arn:aws:iam::000000000000:role/flink-exec";
+
+ /** The Flink {@code RuntimeEnvironment} under test, e.g. {@code FLINK-1_18} or {@code FLINK-2_3}. */
+ protected abstract String runtime();
+
+ private KinesisAnalyticsV2Client kda;
+ private String applicationName = TestFixtures.uniqueName("flink-app");
+ private Instant createTimestamp;
+ private boolean reachedRunning;
+
+ @BeforeAll
+ void setup() {
+ kda = TestFixtures.kinesisAnalyticsV2Client();
+ }
+
+ @AfterAll
+ void cleanup() {
+ if (kda != null) {
+ if (applicationName != null && createTimestamp != null) {
+ try {
+ ensureStopped();
+ kda.deleteApplication(DeleteApplicationRequest.builder()
+ .applicationName(applicationName)
+ .createTimestamp(createTimestamp)
+ .build());
+ } catch (Exception e) {
+ // Tolerated (best-effort teardown) but logged with context per AGENTS.md.
+ System.err.println("[WARN] AfterAll cleanup failed for application "
+ + applicationName + ": " + e.getMessage());
+ }
+ }
+ kda.close();
+ }
+ }
+
+ @Test
+ @Order(1)
+ void createApplicationLandsReady() {
+ // runtime() is passed as a String: FLINK-2_3 is newer than this SDK's RuntimeEnvironment enum
+ // (2.44.14). The generated builder supports the String overload; assert via
+ // runtimeEnvironmentAsString() so both the enum-known (1.18) and newer (2.3) values work.
+ CreateApplicationResponse response = kda.createApplication(CreateApplicationRequest.builder()
+ .applicationName(applicationName)
+ .runtimeEnvironment(runtime())
+ .serviceExecutionRole(ROLE)
+ .build());
+
+ ApplicationDetail detail = response.applicationDetail();
+ assertThat(detail.applicationName()).isEqualTo(applicationName);
+ assertThat(detail.applicationARN()).contains(":kinesisanalytics:");
+ // AWS-faithful: a freshly created application is READY, not RUNNING.
+ assertThat(detail.applicationStatus()).isEqualTo(ApplicationStatus.READY);
+ assertThat(detail.runtimeEnvironmentAsString()).isEqualTo(runtime());
+ createTimestamp = detail.createTimestamp();
+ }
+
+ @Test
+ @Order(2)
+ void startApplicationReachesRunning() {
+ requireApp();
+
+ boolean started;
+ try {
+ kda.startApplication(StartApplicationRequest.builder()
+ .applicationName(applicationName)
+ .build());
+ started = true;
+ } catch (KinesisAnalyticsV2Exception e) {
+ // Container provisioning failed (Docker likely unavailable) — skip rather than fail.
+ started = false;
+ }
+ Assumptions.assumeTrue(started,
+ "StartApplication failed (Docker likely unavailable); skipping RUNNING checks");
+
+ // Flink 2.x boots noticeably slower than 1.x (multi-pass JVM config parser), so allow more time.
+ ApplicationDetail detail = waitForStatus(ApplicationStatus.RUNNING, Duration.ofSeconds(300));
+ Assumptions.assumeTrue(detail != null,
+ "Application did not reach RUNNING (Docker/Flink likely unavailable); skipping");
+
+ reachedRunning = true;
+ assertThat(detail.applicationStatus()).isEqualTo(ApplicationStatus.RUNNING);
+ assertThat(detail.runtimeEnvironmentAsString()).isEqualTo(runtime());
+ }
+
+ @Test
+ @Order(3)
+ void listApplicationsIncludesCreated() {
+ requireApp();
+
+ var response = kda.listApplications(ListApplicationsRequest.builder().build());
+ assertThat(response.applicationSummaries())
+ .anyMatch(s -> s.applicationName().equals(applicationName));
+ }
+
+ @Test
+ @Order(4)
+ void stopApplicationReturnsToReady() {
+ requireApp();
+ Assumptions.assumeTrue(reachedRunning,
+ "Application never reached RUNNING; skipping stop");
+
+ kda.stopApplication(StopApplicationRequest.builder()
+ .applicationName(applicationName)
+ .build());
+
+ ApplicationDetail detail = waitForStatus(ApplicationStatus.READY, Duration.ofSeconds(60));
+ assertThat(detail).isNotNull();
+ assertThat(detail.applicationStatus()).isEqualTo(ApplicationStatus.READY);
+ }
+
+ @Test
+ @Order(5)
+ void unsupportedRuntimeRejected() {
+ // Floci only backs FLINK-x_y runtimes with a plain Flink image; the SQL and Studio (Zeppelin)
+ // runtimes are rejected with InvalidArgumentException.
+ assertThatThrownBy(() -> kda.createApplication(CreateApplicationRequest.builder()
+ .applicationName(TestFixtures.uniqueName("flink-bad"))
+ .runtimeEnvironment(RuntimeEnvironment.ZEPPELIN_FLINK_3_0)
+ .serviceExecutionRole(ROLE)
+ .build()))
+ .isInstanceOf(KinesisAnalyticsV2Exception.class);
+ }
+
+ @Test
+ @Order(6)
+ void deleteApplication() {
+ requireApp();
+
+ // AWS rejects DeleteApplication on a non-stopped application (ResourceInUseException), so
+ // ensure it is READY first (it may still be STARTING if it never reached RUNNING in time).
+ ensureStopped();
+ kda.deleteApplication(DeleteApplicationRequest.builder()
+ .applicationName(applicationName)
+ .createTimestamp(createTimestamp)
+ .build());
+ applicationName = null;
+ }
+
+ /** Best-effort: stop the application if it is RUNNING/STARTING so it can be deleted from READY. */
+ private void ensureStopped() {
+ try {
+ ApplicationStatus status = kda.describeApplication(DescribeApplicationRequest.builder()
+ .applicationName(applicationName)
+ .build()).applicationDetail().applicationStatus();
+ if (status == ApplicationStatus.RUNNING || status == ApplicationStatus.STARTING) {
+ kda.stopApplication(StopApplicationRequest.builder()
+ .applicationName(applicationName)
+ .build());
+ waitForStatus(ApplicationStatus.READY, Duration.ofSeconds(60));
+ }
+ } catch (Exception e) {
+ System.err.println("[WARN] ensureStopped failed for application "
+ + applicationName + ": " + e.getMessage());
+ }
+ }
+
+ private ApplicationDetail waitForStatus(ApplicationStatus target, Duration timeout) {
+ Instant deadline = Instant.now().plus(timeout);
+ while (Instant.now().isBefore(deadline)) {
+ ApplicationDetail detail = kda.describeApplication(DescribeApplicationRequest.builder()
+ .applicationName(applicationName)
+ .build()).applicationDetail();
+ if (detail.applicationStatus() == target) {
+ return detail;
+ }
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ break;
+ }
+ }
+ return null;
+ }
+
+ private void requireApp() {
+ Assumptions.assumeTrue(applicationName != null,
+ "Application must exist from earlier ordered test");
+ }
+}
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/KinesisAnalyticsV2Flink118Test.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/KinesisAnalyticsV2Flink118Test.java
new file mode 100644
index 0000000000..b8aeeab145
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/KinesisAnalyticsV2Flink118Test.java
@@ -0,0 +1,13 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.DisplayName;
+
+/** Runs the Managed Flink lifecycle against the Flink 1.x line (FLINK-1_18). */
+@DisplayName("Managed Service for Apache Flink — Flink 1.18")
+class KinesisAnalyticsV2Flink118Test extends AbstractKinesisAnalyticsV2LifecycleTest {
+
+ @Override
+ protected String runtime() {
+ return "FLINK-1_18";
+ }
+}
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/KinesisAnalyticsV2Flink23Test.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/KinesisAnalyticsV2Flink23Test.java
new file mode 100644
index 0000000000..83a58084b2
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/KinesisAnalyticsV2Flink23Test.java
@@ -0,0 +1,13 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.DisplayName;
+
+/** Runs the Managed Flink lifecycle against the Flink 2.x line (FLINK-2_3). */
+@DisplayName("Managed Service for Apache Flink — Flink 2.3")
+class KinesisAnalyticsV2Flink23Test extends AbstractKinesisAnalyticsV2LifecycleTest {
+
+ @Override
+ protected String runtime() {
+ return "FLINK-2_3";
+ }
+}
diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md
index 708fc5e0b1..1d63f6a1bf 100644
--- a/docs/configuration/environment-variables.md
+++ b/docs/configuration/environment-variables.md
@@ -360,6 +360,14 @@ These services spawn Docker containers. They require access to the Docker socket
| `FLOCI_SERVICES_MSK_MOCK` | `false` | When `true`, clusters are created instantly without a real Redpanda container |
| `FLOCI_SERVICES_MSK_DEFAULT_IMAGE` | `redpandadata/redpanda:latest` | Docker image for Kafka/Redpanda brokers |
+### Managed Service for Apache Flink (Kinesis Analytics V2)
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_KINESIS_ANALYTICS_ENABLED` | `true` | Enable the Managed Flink (Kinesis Analytics V2) service |
+| `FLOCI_SERVICES_KINESIS_ANALYTICS_MOCK` | `false` | When `true`, applications start instantly without a real Flink container |
+| `FLOCI_SERVICES_KINESIS_ANALYTICS_DEFAULT_IMAGE` | _(unset)_ | Optional image override; when unset, the image is chosen from the requested `RuntimeEnvironment` (e.g. `FLINK-1_19` → `apache/flink:1.19`) |
+
### ECR (Elastic Container Registry)
| Variable | Default | Description |
diff --git a/docs/index.md b/docs/index.md
index b40ab49ce9..9bd266b971 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -44,6 +44,7 @@ Floci emulates 69 AWS services. See the [Services Overview](services/index.md) f
| Athena | JSON 1.1 |
| Glue Data Catalog + Schema Registry | JSON 1.1 |
| Data Firehose | JSON 1.1 |
+| Managed Service for Apache Flink | JSON 1.1 |
| ECS | JSON 1.1 |
| EC2 | EC2 Query |
| Lightsail | JSON 1.1 |
diff --git a/docs/services/index.md b/docs/services/index.md
index f8b6969bfc..00d8e489a8 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -25,6 +25,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [Cognito](cognito.md) | `POST /` + `X-Amz-Target: AWSCognitoIdentityProviderService.*` | JSON 1.1 | 43 |
| [KMS](kms.md) | `POST /` + `X-Amz-Target: TrentService.*` | JSON 1.1 | 34 |
| [Kinesis](kinesis.md) | `POST /` + `X-Amz-Target: Kinesis_20131202.*` | JSON 1.1 | 24 |
+| [Managed Service for Apache Flink](kinesisanalytics.md) | `POST /` + `X-Amz-Target: KinesisAnalytics_20180523.*` | JSON 1.1 | 7 |
| [Secrets Manager](secrets-manager.md) | `POST /` + `X-Amz-Target: secretsmanager.*` | JSON 1.1 | 16 |
| [Step Functions](step-functions.md) | `POST /` + `X-Amz-Target: AmazonStatesService.*` | JSON 1.1 | 19 |
| [CloudFormation](cloudformation.md) | `POST /` with `Action=` param | Query | 19 |
diff --git a/docs/services/kinesisanalytics.md b/docs/services/kinesisanalytics.md
new file mode 100644
index 0000000000..5e4cf83ff3
--- /dev/null
+++ b/docs/services/kinesisanalytics.md
@@ -0,0 +1,227 @@
+# 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.
+
+### Deploying application code (a Flink JAR)
+
+Pass an `ApplicationConfiguration` with an `ApplicationCodeConfiguration` pointing at a JAR in Floci's
+local S3, exactly as with real AWS:
+
+```bash
+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.
+
+```bash
+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:
+
+```bash
+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](https://nightlies.apache.org/flink/flink-docs-stable/docs/ops/state/savepoints/)
+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`.
+
+```bash
+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
+```
+
+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.
+
+### Flink Dashboard access
+
+`CreateApplicationPresignedUrl` (with `UrlType: FLINK_DASHBOARD_URL`) returns a URL to the running
+application's Flink Dashboard — the application must be `RUNNING`:
+
+```bash
+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
+
+```bash
+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
+```
diff --git a/mkdocs.yml b/mkdocs.yml
index 0a7d377b01..1b78a0e8c9 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -85,6 +85,7 @@ nav:
- Cognito: services/cognito.md
- KMS: services/kms.md
- Kinesis: services/kinesis.md
+ - Managed Service for Apache Flink: services/kinesisanalytics.md
- Secrets Manager: services/secrets-manager.md
- CloudFormation: services/cloudformation.md
- Step Functions: services/step-functions.md
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index d1c7771781..3409b2cd21 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -531,6 +531,7 @@ public interface EmulatorConfig {
IamServiceConfig iam();
MskServiceConfig msk();
AmazonMqServiceConfig amazonmq();
+ KinesisAnalyticsServiceConfig kinesisAnalytics();
ElastiCacheServiceConfig elasticache();
MemoryDbServiceConfig memorydb();
RdsServiceConfig rds();
@@ -818,6 +819,23 @@ public interface EmulatorConfig {
String defaultImage();
}
+ interface KinesisAnalyticsServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+
+ /** When true, StartApplication comes up RUNNING immediately with no backing Flink
+ * container. Useful for tests and hosts without a Docker daemon. */
+ @WithDefault("false")
+ boolean mock();
+
+ /**
+ * Optional fixed image used for every application regardless of the requested
+ * {@code RuntimeEnvironment} (private registry mirror, pinned patch). When unset, the image
+ * is chosen from the runtime via {@code KinesisAnalyticsRuntimes.imageFor(runtimeEnvironment)}.
+ */
+ Optional defaultImage();
+ }
+
interface ElastiCacheServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
index 2bc6ffbcb5..598f0fb018 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
@@ -36,6 +36,7 @@ import io.github.hectorvent.floci.services.emr.EmrHandler;
import io.github.hectorvent.floci.services.memorydb.MemoryDbHandler;
import io.github.hectorvent.floci.services.wafv2.WafV2Handler;
import io.github.hectorvent.floci.services.kinesis.KinesisJsonHandler;
+import io.github.hectorvent.floci.services.kinesisanalytics.KinesisAnalyticsV2JsonHandler;
import io.github.hectorvent.floci.services.kms.KmsJsonHandler;
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerJsonHandler;
import io.github.hectorvent.floci.services.ssm.Ec2MessagesJsonHandler;
@@ -75,6 +76,7 @@ public class AwsJson11Controller {
private final CloudWatchLogsHandler cloudWatchLogsHandler;
private final SecretsManagerJsonHandler secretsManagerJsonHandler;
private final KinesisJsonHandler kinesisJsonHandler;
+ private final KinesisAnalyticsV2JsonHandler kinesisAnalyticsV2JsonHandler;
private final ApiGatewayV2JsonHandler apigwV2JsonHandler;
private final KmsJsonHandler kmsJsonHandler;
private final CognitoJsonHandler cognitoJsonHandler;
@@ -113,6 +115,7 @@ public class AwsJson11Controller {
CloudWatchLogsHandler cloudWatchLogsHandler,
SecretsManagerJsonHandler secretsManagerJsonHandler,
KinesisJsonHandler kinesisJsonHandler,
+ KinesisAnalyticsV2JsonHandler kinesisAnalyticsV2JsonHandler,
ApiGatewayV2JsonHandler apigwV2JsonHandler,
KmsJsonHandler kmsJsonHandler, CognitoJsonHandler cognitoJsonHandler,
AcmJsonHandler acmJsonHandler, EcsJsonHandler ecsJsonHandler,
@@ -149,6 +152,7 @@ public class AwsJson11Controller {
this.cloudWatchLogsHandler = cloudWatchLogsHandler;
this.secretsManagerJsonHandler = secretsManagerJsonHandler;
this.kinesisJsonHandler = kinesisJsonHandler;
+ this.kinesisAnalyticsV2JsonHandler = kinesisAnalyticsV2JsonHandler;
this.apigwV2JsonHandler = apigwV2JsonHandler;
this.kmsJsonHandler = kmsJsonHandler;
this.cognitoJsonHandler = cognitoJsonHandler;
@@ -218,6 +222,7 @@ public class AwsJson11Controller {
case "logs" -> cloudWatchLogsHandler.handle(action, request, region);
case "secretsmanager" -> secretsManagerJsonHandler.handle(action, request, region);
case "kinesis" -> kinesisJsonHandler.handle(action, request, region);
+ case "kinesisanalytics" -> kinesisAnalyticsV2JsonHandler.handle(action, request, region);
case "apigatewayv2" -> apigwV2JsonHandler.handle(action, request, region);
case "kms" -> kmsJsonHandler.handle(action, request, region);
case "cognito-idp" -> cognitoJsonHandler.handle(action, request, region);
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 0bf6858f9b..d2fd226ee7 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -178,6 +178,11 @@ public class ResolvedServiceCatalog {
"kinesis", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON, ServiceProtocol.CBOR),
Set.of("Kinesis_20131202."), Set.of("kinesis"), Set.of(), Set.of()),
+ descriptor("kinesisanalytics", "kinesisanalytics",
+ config.services().kinesisAnalytics().enabled(), true,
+ "kinesisanalytics", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON),
+ Set.of("KinesisAnalytics_20180523."), Set.of("kinesisanalytics"), Set.of(), Set.of()),
descriptor("kms", "kms", config.services().kms().enabled(), true,
"kms", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
diff --git a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java
index 58af767a5c..5580dc0b26 100644
--- a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java
+++ b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.ec2.Ec2MetadataServer;
import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
import io.github.hectorvent.floci.services.floci.ui.FlociUiManager;
import io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager;
+import io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheMemcachedContainerManager;
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
@@ -75,6 +76,7 @@ public class EmulatorLifecycle {
private final NeptuneContainerManager neptuneContainerManager;
private final NeptuneProxyManager neptuneProxyManager;
private final RabbitMqManager rabbitMqManager;
+ private final FlinkContainerManager flinkContainerManager;
private final RdsService rdsService;
private final ElbV2Service elbV2Service;
private final InitializationHooksRunner initializationHooksRunner;
@@ -104,6 +106,7 @@ public class EmulatorLifecycle {
NeptuneContainerManager neptuneContainerManager,
NeptuneProxyManager neptuneProxyManager,
RabbitMqManager rabbitMqManager,
+ FlinkContainerManager flinkContainerManager,
RdsService rdsService,
ElbV2Service elbV2Service,
InitializationHooksRunner initializationHooksRunner,
@@ -132,6 +135,7 @@ public class EmulatorLifecycle {
this.neptuneContainerManager = neptuneContainerManager;
this.neptuneProxyManager = neptuneProxyManager;
this.rabbitMqManager = rabbitMqManager;
+ this.flinkContainerManager = flinkContainerManager;
this.rdsService = rdsService;
this.elbV2Service = elbV2Service;
this.initializationHooksRunner = initializationHooksRunner;
@@ -279,6 +283,7 @@ public class EmulatorLifecycle {
docDbContainerManager.stopAll();
neptuneContainerManager.stopAll();
rabbitMqManager.stopAll();
+ flinkContainerManager.stopAll();
ecrRegistryManager.shutdown();
flociUiManager.shutdown();
// Centralized teardown for process-bound containers (Lambda warm pool, ECS tasks,
diff --git a/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsRuntimes.java b/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsRuntimes.java
new file mode 100644
index 0000000000..f63db509d0
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsRuntimes.java
@@ -0,0 +1,97 @@
+package io.github.hectorvent.floci.services.kinesisanalytics;
+
+import io.github.hectorvent.floci.core.common.AwsException;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Catalog of Managed Service for Apache Flink runtime environments Floci supports, mapping each
+ * AWS-shaped {@code RuntimeEnvironment} (e.g. {@code FLINK-1_18}) to the Docker image tag that
+ * {@link container.FlinkContainerManager} launches for the JobManager.
+ *
+ * Modelled on {@code services/opensearch/OpenSearchVersions}: without this map every application
+ * would boot whatever {@code apache/flink:1.18} resolved to regardless of the requested
+ * {@code RuntimeEnvironment} — a footgun for anyone testing version-specific Flink behaviour. Images
+ * are pinned to the {@code major.minor} tag (guaranteed to exist on Docker Hub; e.g.
+ * {@code apache/flink:1.18} resolves to a concrete 1.18.x).
+ *
+ *
Only the {@code FLINK-1_x} runtimes are in scope — they map to a plain Flink JobManager image.
+ * The {@code SQL-1_0} and {@code ZEPPELIN-FLINK-*} (Studio) runtimes have no equivalent stock image
+ * and are rejected by {@link #validate(String)}.
+ */
+public final class KinesisAnalyticsRuntimes {
+
+ /** Default runtime when {@code CreateApplication} omits {@code RuntimeEnvironment}. AWS actually
+ * requires the field, so this is only a defensive fallback for {@link #imageFor(String)}. */
+ public static final String DEFAULT_RUNTIME = "FLINK-1_20";
+
+ private static final Map RUNTIME_TO_IMAGE = new LinkedHashMap<>();
+
+ static {
+ // Pinned to major.minor tags — reproducible and guaranteed present on Docker Hub. The set
+ // mirrors the runtimes AWS Managed Service for Apache Flink offers: the 2.x line, plus the
+ // supported 1.x versions. AWS does not offer FLINK-1_16 / FLINK-1_17, so they are omitted.
+ RUNTIME_TO_IMAGE.put("FLINK-2_3", "apache/flink:2.3");
+ RUNTIME_TO_IMAGE.put("FLINK-2_2", "apache/flink:2.2");
+ RUNTIME_TO_IMAGE.put("FLINK-2_1", "apache/flink:2.1");
+ RUNTIME_TO_IMAGE.put("FLINK-2_0", "apache/flink:2.0");
+ RUNTIME_TO_IMAGE.put("FLINK-1_20", "apache/flink:1.20");
+ RUNTIME_TO_IMAGE.put("FLINK-1_19", "apache/flink:1.19");
+ RUNTIME_TO_IMAGE.put("FLINK-1_18", "apache/flink:1.18");
+ RUNTIME_TO_IMAGE.put("FLINK-1_15", "apache/flink:1.15");
+ }
+
+ private KinesisAnalyticsRuntimes() {
+ }
+
+ /** Runtimes Floci supports, newest-first. */
+ public static List supportedRuntimes() {
+ return List.copyOf(RUNTIME_TO_IMAGE.keySet());
+ }
+
+ /**
+ * Pick the image for an application, honouring an optional operator-supplied override that
+ * applies to every application regardless of {@code runtimeEnvironment} (private registry mirror,
+ * pinned patch). When the override is absent this delegates to {@link #imageFor(String)}.
+ */
+ public static String resolveImage(Optional override, String runtimeEnvironment) {
+ return override.filter(o -> !o.isBlank()).orElseGet(() -> imageFor(runtimeEnvironment));
+ }
+
+ /**
+ * Docker image to launch for {@code runtimeEnvironment}. Falls back to the default-runtime image
+ * only when {@code runtimeEnvironment} is null/blank; unsupported runtimes throw — call
+ * {@link #validate(String)} first.
+ */
+ public static String imageFor(String runtimeEnvironment) {
+ if (runtimeEnvironment == null || runtimeEnvironment.isBlank()) {
+ return RUNTIME_TO_IMAGE.get(DEFAULT_RUNTIME);
+ }
+ String image = RUNTIME_TO_IMAGE.get(runtimeEnvironment);
+ if (image == null) {
+ throw new AwsException("InvalidArgumentException",
+ "Unsupported RuntimeEnvironment: " + runtimeEnvironment
+ + ". Supported: " + RUNTIME_TO_IMAGE.keySet(), 400);
+ }
+ return image;
+ }
+
+ /**
+ * Throws {@code InvalidArgumentException} when {@code runtimeEnvironment} is set but not supported.
+ * A null/blank value is allowed — callers that accept an omitted value fall back to
+ * {@link #DEFAULT_RUNTIME}. (Floci's service requires the field, so blanks are rejected upstream.)
+ */
+ public static void validate(String runtimeEnvironment) {
+ if (runtimeEnvironment == null || runtimeEnvironment.isBlank()) {
+ return;
+ }
+ if (!RUNTIME_TO_IMAGE.containsKey(runtimeEnvironment)) {
+ throw new AwsException("InvalidArgumentException",
+ "Unsupported RuntimeEnvironment: " + runtimeEnvironment
+ + ". Supported: " + RUNTIME_TO_IMAGE.keySet(), 400);
+ }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsV2JsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsV2JsonHandler.java
new file mode 100644
index 0000000000..fa25a245a9
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsV2JsonHandler.java
@@ -0,0 +1,379 @@
+package io.github.hectorvent.floci.services.kinesisanalytics;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsErrorResponse;
+import io.github.hectorvent.floci.services.kinesisanalytics.model.FlinkApplication;
+import io.github.hectorvent.floci.services.kinesisanalytics.model.Snapshot;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Dispatches Kinesis Analytics V2 (Managed Service for Apache Flink) actions for the
+ * {@code application/x-amz-json-1.1} protocol, routed here by {@code AwsJson11Controller}
+ * on the {@code KinesisAnalytics_20180523.} target prefix.
+ */
+@ApplicationScoped
+public class KinesisAnalyticsV2JsonHandler {
+
+ private final KinesisAnalyticsV2Service service;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public KinesisAnalyticsV2JsonHandler(KinesisAnalyticsV2Service service, ObjectMapper objectMapper) {
+ this.service = service;
+ this.objectMapper = objectMapper;
+ }
+
+ public Response handle(String action, JsonNode request, String region) {
+ return switch (action) {
+ case "CreateApplication" -> handleCreateApplication(request);
+ case "CreateApplicationPresignedUrl" -> handleCreateApplicationPresignedUrl(request);
+ case "DescribeApplication" -> handleDescribeApplication(request);
+ case "ListApplications" -> handleListApplications(request);
+ case "StartApplication" -> handleStartApplication(request);
+ case "StopApplication" -> handleStopApplication(request);
+ case "UpdateApplication" -> handleUpdateApplication(request);
+ case "DeleteApplication" -> handleDeleteApplication(request);
+ case "TagResource" -> handleTagResource(request);
+ case "UntagResource" -> handleUntagResource(request);
+ case "ListTagsForResource" -> handleListTagsForResource(request);
+ case "CreateApplicationSnapshot" -> handleCreateApplicationSnapshot(request);
+ case "DescribeApplicationSnapshot" -> handleDescribeApplicationSnapshot(request);
+ case "ListApplicationSnapshots" -> handleListApplicationSnapshots(request);
+ case "DeleteApplicationSnapshot" -> handleDeleteApplicationSnapshot(request);
+ default -> Response.status(400)
+ .entity(new AwsErrorResponse("UnsupportedOperation",
+ "Operation " + action + " is not supported."))
+ .build();
+ };
+ }
+
+ private Response handleCreateApplication(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ String runtimeEnvironment = request.path("RuntimeEnvironment").asText(null);
+ String serviceExecutionRole = request.path("ServiceExecutionRole").asText(null);
+ String applicationDescription = request.path("ApplicationDescription").asText(null);
+ String applicationMode = request.path("ApplicationMode").asText(null);
+
+ // Application code (the Flink JAR in S3) + parallelism, from ApplicationConfiguration.
+ JsonNode appConfig = request.path("ApplicationConfiguration");
+ JsonNode s3 = appConfig.path("ApplicationCodeConfiguration").path("CodeContent")
+ .path("S3ContentLocation");
+ String codeBucket = bucketFromArn(s3.path("BucketARN").asText(null));
+ String codeKey = s3.path("FileKey").asText(null);
+ String codeVersion = s3.path("ObjectVersion").asText(null);
+ int parallelism = appConfig.path("FlinkApplicationConfiguration")
+ .path("ParallelismConfiguration").path("Parallelism").asInt(1);
+ Map> environmentProperties =
+ parsePropertyGroups(appConfig.path("EnvironmentProperties").path("PropertyGroups"));
+ JsonNode snapshotsEnabledNode = appConfig.path("ApplicationSnapshotConfiguration").path("SnapshotsEnabled");
+ Boolean snapshotsEnabled = snapshotsEnabledNode.isMissingNode() || snapshotsEnabledNode.isNull()
+ ? null : snapshotsEnabledNode.asBoolean();
+
+ FlinkApplication app = service.createApplication(applicationName, runtimeEnvironment,
+ serviceExecutionRole, applicationDescription, applicationMode,
+ codeBucket, codeKey, codeVersion, parallelism, parseTags(request.path("Tags")),
+ environmentProperties, snapshotsEnabled);
+ return applicationDetailResponse(app);
+ }
+
+ private Response handleCreateApplicationPresignedUrl(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ String urlType = request.path("UrlType").asText(null);
+ Long sessionExpirationDurationInSeconds = request.hasNonNull("SessionExpirationDurationInSeconds")
+ ? request.path("SessionExpirationDurationInSeconds").asLong() : null;
+ String url = service.createApplicationPresignedUrl(applicationName, urlType,
+ sessionExpirationDurationInSeconds);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("AuthorizedUrl", url);
+ return Response.ok(response).build();
+ }
+
+ /** Extracts the bucket name from an S3 bucket ARN ({@code arn:aws:s3:::bucket}). */
+ private static String bucketFromArn(String bucketArn) {
+ if (bucketArn == null) {
+ return null;
+ }
+ String prefix = "arn:aws:s3:::";
+ return bucketArn.startsWith(prefix) ? bucketArn.substring(prefix.length()) : bucketArn;
+ }
+
+ private Response handleDescribeApplication(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ return applicationDetailResponse(service.describeApplication(applicationName));
+ }
+
+ private Response handleListApplications(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode summaries = response.putArray("ApplicationSummaries");
+ for (FlinkApplication app : service.listApplications()) {
+ ObjectNode summary = summaries.addObject();
+ summary.put("ApplicationName", app.getApplicationName());
+ summary.put("ApplicationARN", app.getApplicationArn());
+ summary.put("ApplicationStatus", app.getApplicationStatus().name());
+ summary.put("ApplicationVersionId", app.getApplicationVersionId());
+ summary.put("RuntimeEnvironment", app.getRuntimeEnvironment());
+ if (app.getApplicationMode() != null) {
+ summary.put("ApplicationMode", app.getApplicationMode());
+ }
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response handleStartApplication(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ service.startApplication(applicationName);
+ // AWS StartApplication returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleStopApplication(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ service.stopApplication(applicationName);
+ // AWS StopApplication returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleUpdateApplication(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ // CurrentApplicationVersionId gates the update (optimistic concurrency); the service rejects a
+ // stale or missing value.
+ Long currentVersionId = request.hasNonNull("CurrentApplicationVersionId")
+ ? request.path("CurrentApplicationVersionId").asLong()
+ : null;
+ String serviceExecutionRole = request.path("ServiceExecutionRoleUpdate").asText(null);
+
+ // ApplicationConfigurationUpdate.ApplicationCodeConfigurationUpdate.CodeContentUpdate
+ // .S3ContentLocationUpdate: a new JAR location to redeploy in place.
+ JsonNode appCfgUpdate = request.path("ApplicationConfigurationUpdate");
+ JsonNode s3Update = appCfgUpdate.path("ApplicationCodeConfigurationUpdate")
+ .path("CodeContentUpdate").path("S3ContentLocationUpdate");
+ String codeBucket = bucketFromArn(s3Update.path("BucketARNUpdate").asText(null));
+ String codeKey = s3Update.path("FileKeyUpdate").asText(null);
+ String codeVersion = s3Update.path("ObjectVersionUpdate").asText(null);
+ JsonNode parallelismUpdate = appCfgUpdate.path("FlinkApplicationConfigurationUpdate")
+ .path("ParallelismConfigurationUpdate").path("ParallelismUpdate");
+ Integer parallelism = parallelismUpdate.isMissingNode() || parallelismUpdate.isNull()
+ ? null : parallelismUpdate.asInt();
+ JsonNode snapshotsEnabledUpdate = appCfgUpdate.path("ApplicationSnapshotConfigurationUpdate")
+ .path("SnapshotsEnabledUpdate");
+ Boolean snapshotsEnabled = snapshotsEnabledUpdate.isMissingNode() || snapshotsEnabledUpdate.isNull()
+ ? null : snapshotsEnabledUpdate.asBoolean();
+
+ return applicationDetailResponse(service.updateApplication(applicationName, currentVersionId,
+ serviceExecutionRole, codeBucket, codeKey, codeVersion, parallelism, snapshotsEnabled));
+ }
+
+ private Response handleDeleteApplication(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ // CreateTimestamp is epoch seconds on the wire (possibly fractional); the service validates it
+ // against the stored value.
+ Instant createTimestamp = request.hasNonNull("CreateTimestamp")
+ ? Instant.ofEpochMilli(Math.round(request.path("CreateTimestamp").asDouble() * 1000))
+ : null;
+ service.deleteApplication(applicationName, createTimestamp);
+ // AWS DeleteApplication returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleCreateApplicationSnapshot(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ String snapshotName = request.path("SnapshotName").asText(null);
+ service.createApplicationSnapshot(applicationName, snapshotName);
+ // AWS CreateApplicationSnapshot returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleDescribeApplicationSnapshot(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ String snapshotName = request.path("SnapshotName").asText(null);
+ Snapshot snapshot = service.describeApplicationSnapshot(applicationName, snapshotName);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("SnapshotDetails", snapshotDetailNode(snapshot));
+ return Response.ok(response).build();
+ }
+
+ private Response handleListApplicationSnapshots(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode summaries = response.putArray("SnapshotSummaries");
+ for (Snapshot snapshot : service.listApplicationSnapshots(applicationName)) {
+ summaries.add(snapshotDetailNode(snapshot));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response handleDeleteApplicationSnapshot(JsonNode request) {
+ String applicationName = request.path("ApplicationName").asText(null);
+ String snapshotName = request.path("SnapshotName").asText(null);
+ Instant snapshotCreationTimestamp = request.hasNonNull("SnapshotCreationTimestamp")
+ ? Instant.ofEpochMilli(Math.round(request.path("SnapshotCreationTimestamp").asDouble() * 1000))
+ : null;
+ service.deleteApplicationSnapshot(applicationName, snapshotName, snapshotCreationTimestamp);
+ // AWS DeleteApplicationSnapshot returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private ObjectNode snapshotDetailNode(Snapshot snapshot) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("SnapshotName", snapshot.getSnapshotName());
+ node.put("SnapshotStatus", snapshot.getSnapshotStatus().name());
+ node.put("ApplicationVersionId", snapshot.getApplicationVersionId());
+ if (snapshot.getSnapshotCreationTimestamp() != null) {
+ node.put("SnapshotCreationTimestamp", snapshot.getSnapshotCreationTimestamp().toEpochMilli() / 1000.0);
+ }
+ if (snapshot.getRuntimeEnvironment() != null) {
+ node.put("RuntimeEnvironment", snapshot.getRuntimeEnvironment());
+ }
+ return node;
+ }
+
+ private Response handleTagResource(JsonNode request) {
+ String resourceArn = request.path("ResourceARN").asText(null);
+ service.tagResource(resourceArn, parseTags(request.path("Tags")));
+ // AWS TagResource returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleUntagResource(JsonNode request) {
+ String resourceArn = request.path("ResourceARN").asText(null);
+ List tagKeys = new ArrayList<>();
+ request.path("TagKeys").forEach(k -> tagKeys.add(k.asText()));
+ service.untagResource(resourceArn, tagKeys);
+ // AWS UntagResource returns an empty body.
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleListTagsForResource(JsonNode request) {
+ String resourceArn = request.path("ResourceARN").asText(null);
+ Map tags = service.listTagsForResource(resourceArn);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Tags", tagsNode(tags));
+ return Response.ok(response).build();
+ }
+
+ /** {@code Tags} is a list of {@code {Key, Value}} objects on this API, not a string map. */
+ private Map parseTags(JsonNode tagsNode) {
+ Map tags = new LinkedHashMap<>();
+ if (tagsNode != null && tagsNode.isArray()) {
+ for (JsonNode tag : tagsNode) {
+ String key = tag.path("Key").asText(null);
+ if (key != null) {
+ tags.put(key, tag.path("Value").asText(null));
+ }
+ }
+ }
+ return tags;
+ }
+
+ private ArrayNode tagsNode(Map tags) {
+ ArrayNode arr = objectMapper.createArrayNode();
+ tags.forEach((k, v) -> {
+ ObjectNode tag = arr.addObject();
+ tag.put("Key", k);
+ if (v != null) {
+ tag.put("Value", v);
+ }
+ });
+ return arr;
+ }
+
+ private Response applicationDetailResponse(FlinkApplication app) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ApplicationDetail", applicationDetailNode(app));
+ return Response.ok(response).build();
+ }
+
+ private ObjectNode applicationDetailNode(FlinkApplication app) {
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("ApplicationARN", app.getApplicationArn());
+ detail.put("ApplicationName", app.getApplicationName());
+ if (app.getApplicationDescription() != null) {
+ detail.put("ApplicationDescription", app.getApplicationDescription());
+ }
+ detail.put("RuntimeEnvironment", app.getRuntimeEnvironment());
+ if (app.getServiceExecutionRole() != null) {
+ detail.put("ServiceExecutionRole", app.getServiceExecutionRole());
+ }
+ detail.put("ApplicationStatus", app.getApplicationStatus().name());
+ detail.put("ApplicationVersionId", app.getApplicationVersionId());
+ if (app.getApplicationMode() != null) {
+ detail.put("ApplicationMode", app.getApplicationMode());
+ }
+ if (app.getCreateTimestamp() != null) {
+ detail.put("CreateTimestamp", app.getCreateTimestamp().toEpochMilli() / 1000.0);
+ }
+ if (app.getLastUpdateTimestamp() != null) {
+ detail.put("LastUpdateTimestamp", app.getLastUpdateTimestamp().toEpochMilli() / 1000.0);
+ }
+ if (app.hasCode()) {
+ detail.set("ApplicationConfigurationDescription", applicationConfigurationNode(app));
+ }
+ return detail;
+ }
+
+ private ObjectNode applicationConfigurationNode(FlinkApplication app) {
+ ObjectNode config = objectMapper.createObjectNode();
+
+ ObjectNode codeDesc = config.putObject("ApplicationCodeConfigurationDescription");
+ codeDesc.put("CodeContentType", "ZIPFILE");
+ ObjectNode s3Desc = codeDesc.putObject("CodeContentDescription")
+ .putObject("S3ApplicationCodeLocationDescription");
+ s3Desc.put("BucketARN", "arn:aws:s3:::" + app.getCodeS3Bucket());
+ s3Desc.put("FileKey", app.getCodeS3Key());
+ if (app.getCodeS3ObjectVersion() != null) {
+ s3Desc.put("ObjectVersion", app.getCodeS3ObjectVersion());
+ }
+
+ config.putObject("FlinkApplicationConfigurationDescription")
+ .putObject("ParallelismConfigurationDescription")
+ .put("Parallelism", app.getParallelism())
+ .put("CurrentParallelism", app.getParallelism());
+
+ if (!app.getEnvironmentProperties().isEmpty()) {
+ ArrayNode groups = config.putObject("EnvironmentPropertyDescriptions")
+ .putArray("PropertyGroupDescriptions");
+ app.getEnvironmentProperties().forEach((groupId, properties) -> {
+ ObjectNode group = groups.addObject();
+ group.put("PropertyGroupId", groupId);
+ ObjectNode map = group.putObject("PropertyMap");
+ properties.forEach(map::put);
+ });
+ }
+
+ config.putObject("ApplicationSnapshotConfigurationDescription")
+ .put("SnapshotsEnabled", app.isSnapshotsEnabled());
+
+ return config;
+ }
+
+ /** {@code ApplicationConfiguration.EnvironmentProperties.PropertyGroups}: a list of
+ * {@code {PropertyGroupId, PropertyMap}} objects, keyed by PropertyGroupId internally since
+ * that's how a Flink app looks a group up via {@code KinesisAnalyticsRuntime.getApplicationProperties()}. */
+ private Map> parsePropertyGroups(JsonNode propertyGroupsNode) {
+ Map> groups = new LinkedHashMap<>();
+ if (propertyGroupsNode != null && propertyGroupsNode.isArray()) {
+ for (JsonNode group : propertyGroupsNode) {
+ String groupId = group.path("PropertyGroupId").asText(null);
+ if (groupId == null) {
+ continue;
+ }
+ Map properties = new LinkedHashMap<>();
+ group.path("PropertyMap").fields().forEachRemaining(
+ entry -> properties.put(entry.getKey(), entry.getValue().asText(null)));
+ groups.put(groupId, properties);
+ }
+ }
+ return groups;
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsV2Service.java b/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsV2Service.java
new file mode 100644
index 0000000000..0d09c98a64
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/KinesisAnalyticsV2Service.java
@@ -0,0 +1,579 @@
+package io.github.hectorvent.floci.services.kinesisanalytics;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.kinesisanalytics.container.FlinkContainerManager;
+import io.github.hectorvent.floci.services.kinesisanalytics.model.ApplicationStatus;
+import io.github.hectorvent.floci.services.kinesisanalytics.model.FlinkApplication;
+import io.github.hectorvent.floci.services.kinesisanalytics.model.Snapshot;
+import io.github.hectorvent.floci.services.kinesisanalytics.model.SnapshotStatus;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.time.Instant;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Control plane for Managed Service for Apache Flink (Kinesis Analytics V2). Holds the
+ * application state machine and delegates the real Flink cluster to {@link FlinkContainerManager}.
+ *
+ * Modelled on {@code AmazonMqService}: {@code CreateApplication} lands in {@code READY} with no
+ * container (AWS-faithful — a created application is not running); {@code StartApplication} spins up
+ * a Flink JobManager container and the readiness poller flips {@code STARTING → RUNNING} once the
+ * JobManager REST API answers; {@code StopApplication} tears the container down and returns to
+ * {@code READY}.
+ */
+@ApplicationScoped
+public class KinesisAnalyticsV2Service {
+
+ private static final Logger LOG = Logger.getLogger(KinesisAnalyticsV2Service.class);
+
+ // AWS: "the maximum number of user-defined application tags is 50" (the stated 200-tag ceiling
+ // on the Tags/TagKeys shapes includes AWS-managed system tags, which floci does not model).
+ private static final int MAX_USER_TAGS = 50;
+
+ // CreateApplicationPresignedUrl's SessionExpirationDurationInSeconds valid range (30 min - 12 hr).
+ private static final long MIN_SESSION_EXPIRATION_SECONDS = 1800;
+ private static final long MAX_SESSION_EXPIRATION_SECONDS = 43200;
+
+ private final StorageBackend storage;
+ private final EmulatorConfig config;
+ private final RegionResolver regionResolver;
+ private final FlinkContainerManager containerManager;
+ private final ScheduledExecutorService poller = Executors.newSingleThreadScheduledExecutor();
+
+ @Inject
+ public KinesisAnalyticsV2Service(StorageFactory storageFactory, EmulatorConfig config,
+ RegionResolver regionResolver,
+ FlinkContainerManager containerManager) {
+ this.storage = storageFactory.create("kinesisanalytics", "kinesisanalytics-applications.json",
+ new TypeReference