diff --git a/Makefile b/Makefile
index 28861b3da0..ff4d83ce27 100644
--- a/Makefile
+++ b/Makefile
@@ -285,6 +285,7 @@ aws-data-sync-botocore: ## Regenerate only the AWS data derived from botocore, s
$(PYTHON) tools/aws/regen_payment_cryptography_shapes.py
$(PYTHON) tools/aws/regen_payment_cryptography_data_shapes.py
$(PYTHON) tools/aws/regen_securityhub_shapes.py
+ $(PYTHON) tools/aws/regen_rekognition_shapes.py
$(PYTHON) tools/aws/regen_iam_shapes.py
$(PYTHON) tools/aws/regen_sts_shapes.py
$(PYTHON) tools/aws/regen_apigateway_types.py
@@ -394,6 +395,10 @@ aws-data-check-botocore: ## The AWS data derived from botocore must match a fres
echo "error: Security Hub request shapes are out of date; run 'make aws-data-sync'."; \
exit 1; \
}
+ @$(PYTHON) tools/aws/regen_rekognition_shapes.py --check || { \
+ echo "error: Rekognition request shapes are out of date; run 'make aws-data-sync'."; \
+ exit 1; \
+ }
@$(PYTHON) tools/aws/regen_apigateway_types.py --check || { \
echo "error: API Gateway integration types are out of date; run 'make aws-data-sync'."; \
exit 1; \
diff --git a/docs/services/index.md b/docs/services/index.md
index 2ff3fa78d9..71c16f44d5 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -142,7 +142,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 | 14 |
| [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 |
+| [Rekognition](rekognition.md) | `POST /` + `X-Amz-Target: RekognitionService.*` | JSON 1.1 | 14 |
| [Translate](translate.md) | `POST /` + `X-Amz-Target: AWSShineFrontendService_20170701.*` | JSON 1.1 | 3 |
| [Transcribe](transcribe.md) | `POST /` + `X-Amz-Target: Transcribe.*` | JSON 1.1 | 8 |
| [Pricing](pricing.md) | `POST /` + `X-Amz-Target: AWSPriceListService.*` | JSON 1.1 | 5 |
diff --git a/docs/services/rekognition.md b/docs/services/rekognition.md
index 5146a43703..ea53306e4f 100644
--- a/docs/services/rekognition.md
+++ b/docs/services/rekognition.md
@@ -8,6 +8,15 @@
| Action | Description |
| --- | --- |
+| `CreateCollection` | Create an account- and region-scoped face collection |
+| `DeleteCollection` | Delete a collection and all its indexed face records |
+| `DescribeCollection` | Return collection metadata, face count, and model version |
+| `ListCollections` | List collections with pagination |
+| `IndexFaces` | Store configured face detections in a collection |
+| `ListFaces` | List indexed face metadata with pagination and face ID filtering |
+| `DeleteFaces` | Remove indexed face records |
+| `SearchFaces` | Search a collection using an indexed face ID |
+| `SearchFacesByImage` | Search a collection using the largest configured face in an image |
| `DetectLabels` | Detect objects, scenes, and concepts in an image |
| `DetectFaces` | Detect faces in an image and their attributes |
| `DetectText` | Detect text in an image |
@@ -17,11 +26,12 @@
## Emulation Behavior
-- **Stub responses:** every action returns a fixed, AWS-shaped response. No image
+- **Stub image analysis:** image-analysis actions return fixed, AWS-shaped responses. No image
analysis is performed: what an image shows never changes the result.
- **Images are checked as Rekognition checks them:** an image Rekognition refuses is
refused here, with Rekognition's error, before any response. Measured against
- Rekognition in us-east-2, for each operation and for both `Bytes` and `S3Object`:
+ Rekognition in us-east-2 for the synchronous image-analysis operations and for both
+ `Bytes` and `S3Object`. Collection image operations reuse this validation:
- Anything but a JPEG or PNG (WebP, GIF, other bytes) is refused with
`InvalidImageFormatException`, and so is a cut-off or hollow file the way Rekognition
judges it: a PNG without an `IDAT` or `IEND` chunk, or a JPEG cut inside its headers or
@@ -62,8 +72,7 @@
- **Both `Bytes` and `S3Object`:** supplying both is accepted rather than rejected,
since nothing in the Rekognition API model declares that combination invalid. The
bytes are what is checked.
-- **Out of scope:** face-collection persistence (`CreateCollection`,
- `IndexFaces`, `SearchFaces`), custom-model training (`Projects`, `Datasets`,
+- **Out of scope:** 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.
@@ -73,6 +82,8 @@
| Variable | Default | Description |
|---|---|---|
| `FLOCI_SERVICES_REKOGNITION_ENABLED` | `true` | Enable or disable the service |
+| `FLOCI_STORAGE_SERVICES_REKOGNITION_MODE` | global storage mode | Collection and face metadata storage: `memory`, `persistent`, `hybrid`, or `wal` |
+| `FLOCI_STORAGE_SERVICES_REKOGNITION_FLUSH_INTERVAL_MS` | `5000` | Metadata flush interval in hybrid mode |
| `AI_MOCK_CONFIG` | unset | Path to a shared mock-response config file — see "Mock Responses" below |
## Mock Responses
@@ -105,11 +116,82 @@ when its modification time changes, so it can be edited without restarting the e
missing file, an unset `AI_MOCK_CONFIG`, or no matching entry all fall back to the default
stub.
+## Face Collections
+
+Collections and their indexed face records are isolated by account and region. They use
+Floci's configured storage backend, survive restarts in durable modes, and are removed by
+emulator reset. Deleting a collection removes its faces. Creating an existing collection
+returns `ResourceAlreadyExistsException`; operations on a missing collection return
+`ResourceNotFoundException`. Collection names are case-sensitive.
+
+Face records are stored separately from collection metadata. Durable modes partition faces
+by collection into 32 shards, so indexing and deleting faces write only affected shards
+and leave other collections untouched. WAL mode journals individual face changes.
+
+`IndexFaces` stores the `FaceDetails` from the same `DetectFaces` mock configuration used
+by synchronous detection. Without a matching mock, it returns empty `FaceRecords` and
+`UnindexedFaces`, consistent with the default empty face detection. For example:
+
+```json
+{
+ "rekognition": {
+ "my-bucket/person.jpg": {
+ "DetectFaces": {
+ "FaceDetails": [{
+ "BoundingBox": { "Width": 0.4, "Height": 0.4, "Left": 0.1, "Top": 0.1 },
+ "Confidence": 99.9
+ }]
+ }
+ }
+ }
+}
+```
+
+Upload a valid JPEG or PNG at that S3 key before indexing. Face IDs and image IDs are
+generated by Floci. Re-indexing the same image reference, face position, and
+`ExternalImageId` returns the existing records. `MaxFaces` selects the largest bounding
+boxes, up to 100; remaining detections appear in `UnindexedFaces` with reason
+`EXCEEDS_MAX_FACES`. `DetectionAttributes` and `QualityFilter` do not change configured
+detections; supply the desired attributes and quality in the mock file. The collection
+model version is an emulated `7.0`, independent of the synchronous stub model version.
+
+`ListCollections` and `ListFaces` accept `MaxResults` and opaque `NextToken` cursors.
+Results are ordered by collection ID or face ID. `MaxResults: 0` returns an empty page
+with a continuation token when results remain; resuming with a positive page size returns
+those results. Tokens are scoped to the account, region, operation, and filters, remain
+within the 255-character limit, and expire when the emulator restarts.
+`ListFaces` also supports `FaceIds` filtering. User association actions are not implemented,
+so `UserCount` is zero and a `UserId` filter returns no faces. Creation-time tags are
+retained; collection tagging APIs are not implemented.
+
+Search is deterministic and does no biometric analysis. A match requires the same image
+reference and bounding-box position, and returns similarity `100`. S3 references include
+bucket, key, and optional version; equal bytes at different S3 keys are distinct. Raw image
+bytes are never persisted. `SearchFaces` excludes the source face itself, so indexing the
+same reference under another `ExternalImageId` allows a match. `SearchFacesByImage` uses
+the largest configured detection and returns `InvalidParameterException` if there are no
+configured faces. Both search operations enforce `MaxFaces` and validate
+`FaceMatchThreshold`; every deterministic match meets any valid threshold from 0 to 100.
+
+These semantics support local collection lifecycle and application workflow tests.
+They do not reproduce AWS's face recognition model or quality filtering.
+
+The AWS action contracts are documented in the
+[Rekognition API Reference](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateCollection.html)
+and [face collection guide](https://docs.aws.amazon.com/rekognition/latest/dg/collections.html).
+
## Examples
```bash
export AWS_ENDPOINT_URL=http://localhost:4566
+aws rekognition create-collection --collection-id tenant-1
+aws rekognition index-faces --collection-id tenant-1 \
+ --external-image-id person-1 \
+ --image '{"S3Object":{"Bucket":"my-bucket","Name":"person.jpg"}}'
+aws rekognition list-faces --collection-id tenant-1
+aws rekognition delete-collection --collection-id tenant-1
+
aws rekognition detect-labels \
--image '{"S3Object":{"Bucket":"my-bucket","Name":"photo.jpg"}}' \
--endpoint-url $AWS_ENDPOINT_URL
diff --git a/pom.xml b/pom.xml
index c6ce737b60..4886d46496 100644
--- a/pom.xml
+++ b/pom.xml
@@ -350,6 +350,12 @@
+
+ software.amazon.awssdk
+ rekognition
+ ${aws.sdk.version}
+ test
+
software.amazon.awssdk
accessanalyzer
diff --git a/src/main/java/io/floci/aws/config/EmulatorConfig.java b/src/main/java/io/floci/aws/config/EmulatorConfig.java
index 8dea71aeb7..1bcd293352 100644
--- a/src/main/java/io/floci/aws/config/EmulatorConfig.java
+++ b/src/main/java/io/floci/aws/config/EmulatorConfig.java
@@ -357,6 +357,7 @@ public interface EmulatorConfig {
}
interface ServiceStorageOverrides {
+ RekognitionStorageConfig rekognition();
SsmStorageConfig ssm();
SqsStorageConfig sqs();
S3StorageConfig s3();
@@ -409,6 +410,13 @@ public interface EmulatorConfig {
SageMakerStorageConfig sagemaker();
}
+ interface RekognitionStorageConfig {
+ Optional mode();
+
+ @WithDefault("5000")
+ long flushIntervalMs();
+ }
+
interface ApsStorageConfig {
Optional mode();
diff --git a/src/main/java/io/floci/aws/core/common/RequestConstraintCheck.java b/src/main/java/io/floci/aws/core/common/RequestConstraintCheck.java
index 16e22ace8a..cc8fe7ec62 100644
--- a/src/main/java/io/floci/aws/core/common/RequestConstraintCheck.java
+++ b/src/main/java/io/floci/aws/core/common/RequestConstraintCheck.java
@@ -30,7 +30,7 @@ public final class RequestConstraintCheck {
AwsException type(String path, String type);
/** {@code size} (a length, a count or a number's value) is outside {@code min}..{@code max}. */
- AwsException bounds(String path, String type, Long min, Long max, long size);
+ AwsException bounds(String path, String type, Long min, Long max, Number size);
/** A string does not match the shape's {@code pattern}. */
AwsException pattern(String path, String pattern);
@@ -51,9 +51,11 @@ public final class RequestConstraintCheck {
}
@Override
- public AwsException bounds(String path, String type, Long min, Long max, long size) {
- String measure = "integer".equals(type) || "long".equals(type) ? "value" : "length";
- return min != null && size < min
+ public AwsException bounds(String path, String type, Long min, Long max, Number size) {
+ boolean fractional = "float".equals(type) || "double".equals(type);
+ String measure = fractional || "integer".equals(type) || "long".equals(type) ? "value" : "length";
+ boolean below = min != null && (fractional ? size.doubleValue() < min : size.longValue() < min);
+ return below
? invalid(path, "Member must have " + measure + " greater than or equal to " + min)
: invalid(path, "Member must have " + measure + " less than or equal to " + max);
}
@@ -140,15 +142,18 @@ public final class RequestConstraintCheck {
case "list" -> value.isArray();
case "string" -> value.isTextual();
case "boolean" -> value.isBoolean();
- case "integer", "long" -> value.isIntegralNumber() && value.canConvertToLong();
+ case "integer" -> value.isIntegralNumber() && value.canConvertToInt();
+ case "long" -> value.isIntegralNumber() && value.canConvertToLong();
+ case "float", "double" -> value.isNumber();
default -> false;
};
if (!validType) {
throw messages.type(path, type);
}
- long size = switch (type) {
+ Number size = switch (type) {
case "string" -> value.textValue().codePointCount(0, value.textValue().length());
case "integer", "long" -> value.longValue();
+ case "float", "double" -> value.doubleValue();
default -> value.size();
};
checkBounds(shape, path, type, size);
@@ -196,10 +201,17 @@ public final class RequestConstraintCheck {
}
}
- private void checkBounds(JsonNode shape, String path, String type, long size) {
+ private void checkBounds(JsonNode shape, String path, String type, Number size) {
Long min = shape.has("min") ? shape.get("min").asLong() : null;
Long max = shape.has("max") ? shape.get("max").asLong() : null;
- if (min != null && size < min || max != null && size > max) {
+ boolean outside;
+ if ("float".equals(type) || "double".equals(type)) {
+ double number = size.doubleValue();
+ outside = !Double.isFinite(number) || min != null && number < min || max != null && number > max;
+ } else {
+ outside = min != null && size.longValue() < min || max != null && size.longValue() > max;
+ }
+ if (outside) {
throw messages.bounds(path, type, min, max, size);
}
}
diff --git a/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java b/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java
index 956ff738ad..64e5c3dbd7 100644
--- a/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java
@@ -667,7 +667,8 @@ public class ResolvedServiceCatalog {
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,
+ "rekognition", storageMode(config.storage().services().rekognition().mode(), config.storage().mode()),
+ config.storage().services().rekognition().flushIntervalMs(), null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("RekognitionService."), Set.of("rekognition"), Set.of(), Set.of()),
descriptor("pricing", "pricing", config.services().pricing().enabled(), true,
diff --git a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationRequestShapes.java b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationRequestShapes.java
index 777552f604..23203695c7 100644
--- a/src/main/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationRequestShapes.java
+++ b/src/main/java/io/floci/aws/services/apigateway/ApiGatewayDocumentationRequestShapes.java
@@ -18,7 +18,7 @@ final class ApiGatewayDocumentationRequestShapes {
}
@Override
- public AwsException bounds(String path, String type, Long min, Long max, long size) {
+ public AwsException bounds(String path, String type, Long min, Long max, Number size) {
return bad(path + " is outside the modeled bounds.");
}
diff --git a/src/main/java/io/floci/aws/services/cloudwatch/logs/CloudWatchLogsRequestShapes.java b/src/main/java/io/floci/aws/services/cloudwatch/logs/CloudWatchLogsRequestShapes.java
index fb9ded8f42..04a3400342 100644
--- a/src/main/java/io/floci/aws/services/cloudwatch/logs/CloudWatchLogsRequestShapes.java
+++ b/src/main/java/io/floci/aws/services/cloudwatch/logs/CloudWatchLogsRequestShapes.java
@@ -33,9 +33,9 @@ final class CloudWatchLogsRequestShapes {
}
@Override
- public AwsException bounds(String path, String type, Long min, Long max, long size) {
+ public AwsException bounds(String path, String type, Long min, Long max, Number size) {
String measure = "integer".equals(type) || "long".equals(type) ? "value" : "length";
- return max != null && size > max
+ return max != null && size.longValue() > max
? violation(path, "Member must have " + measure + " less than or equal to " + max)
: violation(path, "Member must have " + measure + " greater than or equal to " + min);
}
diff --git a/src/main/java/io/floci/aws/services/rekognition/RekognitionCollectionService.java b/src/main/java/io/floci/aws/services/rekognition/RekognitionCollectionService.java
new file mode 100644
index 0000000000..9317b31897
--- /dev/null
+++ b/src/main/java/io/floci/aws/services/rekognition/RekognitionCollectionService.java
@@ -0,0 +1,324 @@
+package io.floci.aws.services.rekognition;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+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.floci.aws.core.common.AiMockConfigLoader;
+import io.floci.aws.core.common.AwsException;
+import io.floci.aws.core.common.Digests;
+import io.floci.aws.core.common.PaginatedResult;
+import io.floci.aws.core.common.Pagination;
+import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.core.common.Resettable;
+import io.floci.aws.core.common.SignedMarkers;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
+import io.floci.aws.core.storage.StorageBackend;
+import io.floci.aws.core.storage.StorageFactory;
+import io.floci.aws.services.rekognition.model.FaceCollection;
+import io.floci.aws.services.rekognition.model.FaceCollection.IndexedFace;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Function;
+
+/** Collection metadata is real state; face detection and matching use deterministic mock data. */
+@ApplicationScoped
+public class RekognitionCollectionService implements Resettable {
+ static final String MODEL_VERSION = "7.0";
+ private final StorageBackend collections;
+ private final AccountAwareStorageBackend