Skip to content

armgit / floci

Public Imported from GitHub
0

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

feat(rekognition): add Amazon Rekognition sync image-analysis actions (#2706)

Ahmed khaledcf6fede45357
diff --git a/README.md b/README.md
index dd6f277f32..8a450caf65 100644
--- a/README.md
+++ b/README.md
@@ -178,7 +178,7 @@ LocalStack's community edition [sunset in March 2026](https://blog.localstack.cl
| CodeBuild | Real Docker execution | No |
| Native binary | ~40 MB | No |
-**83 AWS services. Broad coverage. Free forever.**
+**84 AWS services. Broad coverage. Free forever.**
## Architecture Overview
diff --git a/docs/index.md b/docs/index.md
index 5a82025717..97c39d29bc 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -12,7 +12,7 @@ Floci is a fast, free, and open-source local AWS service emulator built for deve
## Supported Services
-Floci emulates 83 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details.
+Floci emulates 84 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details.
| Service | Protocol |
|---|---|
@@ -117,7 +117,7 @@ docker compose up -d
aws --endpoint-url http://localhost:4566 s3 mb s3://my-bucket
```
-All 83 AWS services are immediately available at `http://localhost:4566`.
+All 84 AWS services are immediately available at `http://localhost:4566`.
[Get started →](getting-started/quick-start.md){ .md-button .md-button--primary }
[View services →](services/index.md){ .md-button }
diff --git a/docs/services/index.md b/docs/services/index.md
index d6d602d3a6..07619f1a48 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -1,6 +1,6 @@
# Services Overview
-Floci emulates 83 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification.
+Floci emulates 84 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification.
This page is the canonical reference for supported service and operation counts. Some services expose separate control-plane and data-plane rows below. Other docs (and the README) should link here rather than duplicating the table.
@@ -101,6 +101,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [CloudTrail](cloudtrail.md) | `POST /` + `X-Amz-Target: com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.*` | JSON 1.1 | 9 |
| [Textract](textract.md) | `POST /` + `X-Amz-Target: Textract.*` | JSON 1.1 | 6 |
| [Comprehend](comprehend.md) | `POST /` + `X-Amz-Target: Comprehend_20171127.*` | JSON 1.1 | 5 |
+| [Rekognition](rekognition.md) | `POST /` + `X-Amz-Target: RekognitionService.*` | JSON 1.1 | 5 |
| [Transcribe](transcribe.md) | `POST /` + `X-Amz-Target: Transcribe.*` | JSON 1.1 | 8 |
| [Pricing](pricing.md) | `POST /` + `X-Amz-Target: AWSPriceListService.*` | JSON 1.1 | 5 |
| [Cost Explorer](ce.md) | `POST /` + `X-Amz-Target: AWSInsightsIndexService.*` | JSON 1.1 | 9 |
diff --git a/docs/services/rekognition.md b/docs/services/rekognition.md
new file mode 100644
index 0000000000..560c96508b
--- /dev/null
+++ b/docs/services/rekognition.md
@@ -0,0 +1,89 @@
+# Rekognition
+
+**Protocol:** JSON 1.1 (`X-Amz-Target: RekognitionService.*`)
+**Endpoint:** `POST http://localhost:4566/`
+
+## Supported Actions
+
+<!-- floci:actions:start -->
+| Action | Description |
+| --- | --- |
+| `DetectLabels` | Detect objects, scenes, and concepts in an image |
+| `DetectFaces` | Detect faces in an image and their attributes |
+| `DetectText` | Detect text in an image |
+| `CompareFaces` | Compare a face in a source image with faces in a target image |
+| `DetectModerationLabels` | Detect unsafe or inappropriate content in an image |
+<!-- floci:actions:end -->
+
+## Emulation Behavior
+
+- **Stub responses:** every action returns a fixed, AWS-shaped response — no real
+ image analysis is performed. `Image`/`SourceImage`/`TargetImage` content is
+ accepted but never decoded, the same way Textract accepts `Document` without
+ reading it.
+- **Content-listing operations return one canned entry:** `DetectLabels` and
+ `DetectText` always report a single stub label/text detection, matching the
+ Textract stub's block-hierarchy convention.
+- **Face/moderation operations return empty results:** `DetectFaces`,
+ `CompareFaces`, and `DetectModerationLabels` always report nothing found
+ (empty `FaceDetails`/`FaceMatches`/`ModerationLabels`) rather than fabricating
+ biometric attributes or a moderation flag for content that was never analyzed
+ — an honest "nothing detected" response, matching the Comprehend PII-detection
+ stub's precedent.
+- **Real input validation:** `Image` (or `SourceImage`/`TargetImage` for
+ `CompareFaces`) is required, must be a JSON structure, and must specify
+ `Bytes` (string-typed) or `S3Object` (structure-typed) — matching AWS's own
+ modeling and rejecting wrong JSON types as `SerializationException`. This is
+ protocol compatibility, not content analysis.
+- **Intentional deviations:** `Bytes`'s content is not validated as
+ well-formed base64 (the `S3Object` shape has no required members in AWS's
+ own model, so its fields aren't validated either), and supplying both
+ `Bytes` and `S3Object` is accepted rather than rejected — nothing in the
+ Rekognition API model declares that combination invalid, and the stub
+ never reads either field's content regardless.
+- **Out of scope:** face-collection persistence (`CreateCollection`,
+ `IndexFaces`, `SearchFaces`), custom-model training (`Projects`, `Datasets`,
+ `ProjectVersions`), live video (`StreamProcessor`), async video jobs
+ (`Start*`/`Get*` Celebrity/Content/Face/Label/Person/Segment/Text detection),
+ and Face Liveness sessions are not implemented.
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_REKOGNITION_ENABLED` | `true` | Enable or disable the service |
+
+## Examples
+
+```bash
+export AWS_ENDPOINT_URL=http://localhost:4566
+
+aws rekognition detect-labels \
+ --image '{"S3Object":{"Bucket":"my-bucket","Name":"photo.jpg"}}' \
+ --endpoint-url $AWS_ENDPOINT_URL
+
+aws rekognition detect-text \
+ --image '{"S3Object":{"Bucket":"my-bucket","Name":"photo.jpg"}}' \
+ --endpoint-url $AWS_ENDPOINT_URL
+
+aws rekognition compare-faces \
+ --source-image '{"S3Object":{"Bucket":"my-bucket","Name":"source.jpg"}}' \
+ --target-image '{"S3Object":{"Bucket":"my-bucket","Name":"target.jpg"}}' \
+ --endpoint-url $AWS_ENDPOINT_URL
+```
+
+## SDK Example (Java)
+
+```java
+RekognitionClient rekognition = RekognitionClient.builder()
+ .endpointOverride(URI.create("http://localhost:4566"))
+ .region(Region.US_EAST_1)
+ .credentialsProvider(StaticCredentialsProvider.create(
+ AwsBasicCredentials.create("test", "test")))
+ .build();
+
+DetectLabelsResponse response = rekognition.detectLabels(req -> req
+ .image(img -> img.s3Object(s3 -> s3.bucket("my-bucket").name("photo.jpg"))));
+
+System.out.println("Labels: " + response.labels());
+```
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 2697b54758..84faf36782 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -658,6 +658,7 @@ public interface EmulatorConfig {
TransferServiceConfig transfer();
TextractServiceConfig textract();
ComprehendServiceConfig comprehend();
+ RekognitionServiceConfig rekognition();
PricingServiceConfig pricing();
DuckConfig duck();
TranscribeServiceConfig transcribe();
@@ -1549,6 +1550,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface RekognitionServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface PricingServiceConfig {
@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 ee92fda1c3..0796c4f1f1 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
@@ -29,6 +29,7 @@ import io.github.hectorvent.floci.services.cur.CurJsonHandler;
import io.github.hectorvent.floci.services.pricing.PricingJsonHandler;
import io.github.hectorvent.floci.services.textract.TextractJsonHandler;
import io.github.hectorvent.floci.services.comprehend.ComprehendJsonHandler;
+import io.github.hectorvent.floci.services.rekognition.RekognitionJsonHandler;
import io.github.hectorvent.floci.services.transcribe.TranscribeJsonHandler;
import io.github.hectorvent.floci.services.apigatewayv2.ApiGatewayV2JsonHandler;
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsHandler;
@@ -102,6 +103,7 @@ public class AwsJson11Controller {
private final TransferHandler transferHandler;
private final TextractJsonHandler textractJsonHandler;
private final ComprehendJsonHandler comprehendJsonHandler;
+ private final RekognitionJsonHandler rekognitionJsonHandler;
private final PricingJsonHandler pricingJsonHandler;
private final TranscribeJsonHandler transcribeJsonHandler;
private final CostExplorerJsonHandler costExplorerJsonHandler;
@@ -146,6 +148,7 @@ public class AwsJson11Controller {
TransferHandler transferHandler,
TextractJsonHandler textractJsonHandler,
ComprehendJsonHandler comprehendJsonHandler,
+ RekognitionJsonHandler rekognitionJsonHandler,
PricingJsonHandler pricingJsonHandler,
TranscribeJsonHandler transcribeJsonHandler,
CostExplorerJsonHandler costExplorerJsonHandler,
@@ -194,6 +197,7 @@ public class AwsJson11Controller {
this.transferHandler = transferHandler;
this.textractJsonHandler = textractJsonHandler;
this.comprehendJsonHandler = comprehendJsonHandler;
+ this.rekognitionJsonHandler = rekognitionJsonHandler;
this.pricingJsonHandler = pricingJsonHandler;
this.transcribeJsonHandler = transcribeJsonHandler;
this.costExplorerJsonHandler = costExplorerJsonHandler;
@@ -273,6 +277,7 @@ public class AwsJson11Controller {
case "transfer" -> transferHandler.handle(action, request, region);
case "textract" -> textractJsonHandler.handle(action, request, region);
case "comprehend" -> comprehendJsonHandler.handle(action, request, region);
+ case "rekognition" -> rekognitionJsonHandler.handle(action, request, region);
case "pricing" -> pricingJsonHandler.handle(action, request, region);
case "transcribe" -> transcribeJsonHandler.handle(action, request, region);
case "ce" -> costExplorerJsonHandler.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 7a72cfd654..46087b4805 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
@@ -450,6 +450,10 @@ public class ResolvedServiceCatalog {
null, null, 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("Comprehend_20171127."), Set.of("comprehend"), Set.of(), Set.of()),
+ descriptor("rekognition", "rekognition", config.services().rekognition().enabled(), true,
+ null, null, 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON),
+ Set.of("RekognitionService."), Set.of("rekognition"), Set.of(), Set.of()),
descriptor("pricing", "pricing", config.services().pricing().enabled(), true,
null, null, 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
diff --git a/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionJsonHandler.java
new file mode 100644
index 0000000000..7ff085a655
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionJsonHandler.java
@@ -0,0 +1,98 @@
+package io.github.hectorvent.floci.services.rekognition;
+import com.fasterxml.jackson.databind.JsonNode;
+import io.github.hectorvent.floci.core.common.AwsErrorResponse;
+import io.github.hectorvent.floci.core.common.AwsException;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+import org.jboss.logging.Logger;
+import java.util.function.Predicate;
+/**
+ * JSON 1.1 handler for Amazon Rekognition API operations.
+ * Dispatches X-Amz-Target: RekognitionService.* actions to {@link RekognitionService}.
+ *
+ * @see <a href="https://docs.aws.amazon.com/rekognition/latest/APIReference/Welcome.html">Rekognition API Reference</a>
+ */
+@ApplicationScoped
+public class RekognitionJsonHandler {
+ private static final Logger LOG = Logger.getLogger(RekognitionJsonHandler.class);
+ private final RekognitionService rekognitionService;
+ @Inject
+ public RekognitionJsonHandler(RekognitionService rekognitionService) {
+ this.rekognitionService = rekognitionService;
+ }
+ /**
+ * Dispatches Rekognition actions received via the AwsJson11Controller.
+ * Only sync image-analysis actions are implemented; face-collection persistence
+ * (CreateCollection/IndexFaces/SearchFaces), custom-model training (Projects/
+ * Datasets/ProjectVersions), live video (StreamProcessor), async video jobs
+ * (the Start and Get pairs for Celebrity/Content/Face/Label/Person/Segment/Text
+ * detection), and Face Liveness sessions are out of scope.
+ */
+ public Response handle(String action, JsonNode request, String region) {
+ LOG.debugv("Rekognition action: {0}", action);
+ return switch (action) {
+ case "DetectLabels" -> {
+ requireImage(request, "Image");
+ yield rekognitionService.detectLabels();
+ }
+ case "DetectFaces" -> {
+ requireImage(request, "Image");
+ yield rekognitionService.detectFaces();
+ }
+ case "DetectText" -> {
+ requireImage(request, "Image");
+ yield rekognitionService.detectText();
+ }
+ case "CompareFaces" -> {
+ requireImage(request, "SourceImage");
+ requireImage(request, "TargetImage");
+ yield rekognitionService.compareFaces();
+ }
+ case "DetectModerationLabels" -> {
+ requireImage(request, "Image");
+ yield rekognitionService.detectModerationLabels();
+ }
+ default -> Response.status(400)
+ .entity(new AwsErrorResponse("UnknownOperationException",
+ "Unknown operation: RekognitionService." + action))
+ .build();
+ };
+ }
+ /**
+ * The Image shape (real content ignored — the response is a fixed stub) is still
+ * required and must carry Bytes or S3Object, matching AWS's own required-member
+ * and one-of-Bytes-or-S3Object modeling for Image/SourceImage/TargetImage.
+ */
+ private void requireImage(JsonNode request, String field) {
+ JsonNode image = request == null ? null : request.get(field);
+ if (image == null || image.isNull()) {
+ throw new AwsException("InvalidParameterException", field + " is a required field.", 400);
+ }
+ if (!image.isObject()) {
+ throw new AwsException("SerializationException",
+ "Unable to unmarshal request; the value for '" + field + "' is not a structure.", 400);
+ }
+ requireCorrectTypeIfPresent(image, "Bytes", JsonNode::isTextual, field);
+ requireCorrectTypeIfPresent(image, "S3Object", JsonNode::isObject, field);
+ if (!image.hasNonNull("Bytes") && !image.hasNonNull("S3Object")) {
+ throw new AwsException("InvalidParameterException",
+ field + " must specify Bytes or S3Object.", 400);
+ }
+ }
+ /**
+ * Bytes (a blob shape, base64-encoded string on the wire) and S3Object (a structure)
+ * must each carry their modeled JSON type when present. Content-level correctness
+ * (valid base64, S3Object.Bucket/Name presence — S3Object has no required members
+ * in the modeled shape) is not validated: this stub never reads image content, and
+ * enforcing more than the wire shape declares would invent stricter validation than
+ * AWS's own model.
+ */
+ private void requireCorrectTypeIfPresent(JsonNode image, String member, Predicate<JsonNode> isCorrectType, String field) {
+ JsonNode value = image.get(member);
+ if (value != null && !value.isNull() && !isCorrectType.test(value)) {
+ throw new AwsException("SerializationException",
+ "Unable to unmarshal request; the value for '" + field + "." + member + "' has the wrong type.", 400);
+ }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionService.java b/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionService.java
new file mode 100644
index 0000000000..50fd5f6a63
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionService.java
@@ -0,0 +1,123 @@
+package io.github.hectorvent.floci.services.rekognition;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+/**
+ * Dummy response builder for Amazon Rekognition. Stateless — every action ignores
+ * the actual image content and returns a fixed but AWS-shaped response.
+ * <p>
+ * Content-listing operations (DetectLabels, DetectText) always return one canned
+ * entry, matching the TextractService stub precedent. Face/moderation operations
+ * (DetectFaces, CompareFaces, DetectModerationLabels) return empty results by
+ * default — an honest "nothing detected" response, rather than fabricating
+ * biometric attributes or a moderation flag for content that was never analyzed,
+ * matching the ComprehendService PII-detection precedent.
+ * <p>
+ * Real detection logic is a planned follow-up; see the tracking issue for scope.
+ *
+ * @see <a href="https://docs.aws.amazon.com/rekognition/latest/APIReference/Welcome.html">Rekognition API Reference</a>
+ */
+@ApplicationScoped
+public class RekognitionService {
+ static final String MODEL_VERSION = "1.0";
+ private final ObjectMapper objectMapper;
+ @Inject
+ public RekognitionService(ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ }
+ /**
+ * DetectLabels — always returns a single stub label.
+ * Response shape: https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectLabels.html
+ */
+ public Response detectLabels() {
+ ObjectNode root = objectMapper.createObjectNode();
+ ArrayNode labels = root.putArray("Labels");
+ ObjectNode label = labels.addObject();
+ label.put("Name", "Floci");
+ label.put("Confidence", 99.9);
+ root.put("LabelModelVersion", MODEL_VERSION);
+ return Response.ok(root).build();
+ }
+ /**
+ * DetectFaces — always reports no faces found.
+ * Response shape: https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectFaces.html
+ */
+ public Response detectFaces() {
+ ObjectNode root = objectMapper.createObjectNode();
+ root.putArray("FaceDetails");
+ return Response.ok(root).build();
+ }
+ /**
+ * DetectText — always returns one stub LINE and its child WORD, matching
+ * Textract's PAGE/LINE/WORD block-hierarchy convention.
+ * Response shape: https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectText.html
+ */
+ public Response detectText() {
+ ObjectNode root = objectMapper.createObjectNode();
+ ArrayNode detections = root.putArray("TextDetections");
+ ObjectNode line = detections.addObject();
+ line.put("DetectedText", "Floci");
+ line.put("Type", "LINE");
+ line.put("Id", 0);
+ line.put("Confidence", 99.9);
+ line.set("Geometry", buildGeometry(0.1, 0.1, 0.15, 0.05));
+ ObjectNode word = detections.addObject();
+ word.put("DetectedText", "Floci");
+ word.put("Type", "WORD");
+ word.put("Id", 1);
+ word.put("ParentId", 0);
+ word.put("Confidence", 99.9);
+ word.set("Geometry", buildGeometry(0.1, 0.1, 0.15, 0.05));
+ root.put("TextModelVersion", MODEL_VERSION);
+ return Response.ok(root).build();
+ }
+ /**
+ * CompareFaces — always reports no matches (SourceImageFace is optional and
+ * legitimately omitted when no face is found in the source image).
+ * Response shape: https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CompareFaces.html
+ */
+ public Response compareFaces() {
+ ObjectNode root = objectMapper.createObjectNode();
+ root.putArray("FaceMatches");
+ root.putArray("UnmatchedFaces");
+ return Response.ok(root).build();
+ }
+ /**
+ * DetectModerationLabels — always reports no moderation labels found.
+ * Response shape: https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html
+ */
+ public Response detectModerationLabels() {
+ ObjectNode root = objectMapper.createObjectNode();
+ root.putArray("ModerationLabels");
+ root.put("ModerationModelVersion", MODEL_VERSION);
+ return Response.ok(root).build();
+ }
+ // Private helpers
+ /**
+ * Builds a Geometry object with BoundingBox and a 4-point Polygon — the same
+ * shape Textract uses (Rekognition's Geometry shape is structurally identical).
+ * @see <a href="https://docs.aws.amazon.com/rekognition/latest/APIReference/API_Geometry.html">Geometry</a>
+ */
+ private ObjectNode buildGeometry(double left, double top, double width, double height) {
+ ObjectNode geometry = objectMapper.createObjectNode();
+ ObjectNode bbox = geometry.putObject("BoundingBox");
+ bbox.put("Width", width);
+ bbox.put("Height", height);
+ bbox.put("Left", left);
+ bbox.put("Top", top);
+ ArrayNode polygon = geometry.putArray("Polygon");
+ addPoint(polygon, left, top);
+ addPoint(polygon, left + width, top);
+ addPoint(polygon, left + width, top + height);
+ addPoint(polygon, left, top + height);
+ return geometry;
+ }
+ private void addPoint(ArrayNode polygon, double x, double y) {
+ ObjectNode point = polygon.addObject();
+ point.put("X", x);
+ point.put("Y", y);
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 9304d659e8..a8dc3b6077 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -508,6 +508,8 @@ floci:
enabled: true
comprehend:
enabled: true
+ rekognition:
+ enabled: true
pricing:
enabled: true
transcribe:
diff --git a/src/test/java/io/github/hectorvent/floci/services/rekognition/RekognitionIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rekognition/RekognitionIntegrationTest.java
new file mode 100644
index 0000000000..1de699d23a
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/rekognition/RekognitionIntegrationTest.java
@@ -0,0 +1,205 @@
+package io.github.hectorvent.floci.services.rekognition;
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.*;
+/**
+ * Integration tests for the Amazon Rekognition stub.
+ * Validates AWS-compatible wire format using RestAssured.
+ * Protocol: JSON 1.1 — Content-Type: application/x-amz-json-1.1, X-Amz-Target: RekognitionService.<Action>
+ */
+@QuarkusTest
+class RekognitionIntegrationTest {
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/rekognition/aws4_request";
+ private static final String S3_IMAGE =
+ "{\"S3Object\":{\"Bucket\":\"my-bucket\",\"Name\":\"photo.jpg\"}}";
+ @Test
+ void detectLabels_returnsStubLabel() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":" + S3_IMAGE + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Labels", hasSize(1))
+ .body("Labels[0].Name", equalTo("Floci"))
+ .body("Labels[0].Confidence", notNullValue())
+ .body("LabelModelVersion", equalTo("1.0"));
+ }
+ @Test
+ void detectLabels_missingImage_returns400() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterException"));
+ }
+ @Test
+ void detectLabels_imageWithoutBytesOrS3Object_returns400() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":{}}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterException"));
+ }
+ @Test
+ void detectLabels_nonObjectImage_returnsSerializationException() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":\"banana\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("SerializationException"));
+ }
+ @Test
+ void detectLabels_nonStringBytes_returnsSerializationException() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":{\"Bytes\":12345}}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("SerializationException"));
+ }
+ @Test
+ void detectLabels_nonObjectS3Object_returnsSerializationException() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":{\"S3Object\":\"not-an-object\"}}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("SerializationException"));
+ }
+ @Test
+ void detectLabels_bothBytesAndS3ObjectAccepted() {
+ // Neither field's content is read, and nothing in the Rekognition model
+ // declares supplying both invalid.
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":{\"Bytes\":\"aGVsbG8=\",\"S3Object\":{\"Bucket\":\"my-bucket\",\"Name\":\"photo.jpg\"}}}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Labels", hasSize(1));
+ }
+ @Test
+ void detectFaces_returnsEmptyFaceDetails() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectFaces")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":" + S3_IMAGE + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("FaceDetails", hasSize(0));
+ }
+ @Test
+ void detectText_returnsLineAndWordDetections() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectText")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":" + S3_IMAGE + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("TextDetections", hasSize(2))
+ .body("TextDetections.Type", hasItems("LINE", "WORD"))
+ .body("TextDetections.findAll { it.Type == 'LINE' }.DetectedText", hasItem("Floci"))
+ .body("TextDetections[0].Geometry.BoundingBox.Width", notNullValue())
+ .body("TextDetections[0].Geometry.Polygon", hasSize(4))
+ .body("TextModelVersion", equalTo("1.0"));
+ }
+ @Test
+ void compareFaces_returnsEmptyMatches() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.CompareFaces")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"SourceImage\":" + S3_IMAGE + ",\"TargetImage\":" + S3_IMAGE + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("FaceMatches", hasSize(0))
+ .body("UnmatchedFaces", hasSize(0));
+ }
+ @Test
+ void compareFaces_missingTargetImage_returns400() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.CompareFaces")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"SourceImage\":" + S3_IMAGE + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterException"));
+ }
+ @Test
+ void detectModerationLabels_returnsEmptyLabels() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.DetectModerationLabels")
+ .header("Authorization", AUTH_HEADER)
+ .body("{\"Image\":" + S3_IMAGE + "}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("ModerationLabels", hasSize(0))
+ .body("ModerationModelVersion", equalTo("1.0"));
+ }
+ @Test
+ void unknownAction_returnsUnknownOperationError() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "RekognitionService.IndexFaces")
+ .header("Authorization", AUTH_HEADER)
+ .body("{}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("UnknownOperationException"));
+ }
+}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index 7df748f452..1fd20634b7 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -298,6 +298,8 @@ floci:
enabled: true
comprehend:
enabled: true
+ rekognition:
+ enabled: true
pricing:
enabled: true
ce:
diff --git a/tools/docs/services.yaml b/tools/docs/services.yaml
index 6940695a9b..ce1d74cb98 100644
--- a/tools/docs/services.yaml
+++ b/tools/docs/services.yaml
@@ -38,6 +38,10 @@ services:
doc: docs/services/comprehend.md
sources:
- { path: src/main/java/io/github/hectorvent/floci/services/comprehend/ComprehendJsonHandler.java, mode: switch }
+ - service: rekognition
+ doc: docs/services/rekognition.md
+ sources:
+ - { path: src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionJsonHandler.java, mode: switch }
- service: docdb
doc: docs/services/docdb.md
sources: