Skip to content

armgit / floci

Public Imported from GitHub
0

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

feat(cloudformation): support S3 Vectors resources (#5853)

andrehoong-px5774e7db8d8f
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationS3VectorsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationS3VectorsTest.java
new file mode 100644
index 0000000000..6eba8e4ad2
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudFormationS3VectorsTest.java
@@ -0,0 +1,536 @@
+package com.floci.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.cloudformation.CloudFormationClient;
+import software.amazon.awssdk.services.cloudformation.model.ChangeSetType;
+import software.amazon.awssdk.services.cloudformation.model.CloudFormationException;
+import software.amazon.awssdk.services.cloudformation.model.DescribeChangeSetResponse;
+import software.amazon.awssdk.services.cloudformation.model.Output;
+import software.amazon.awssdk.services.cloudformation.model.Parameter;
+import software.amazon.awssdk.services.cloudformation.model.ResourceChange;
+import software.amazon.awssdk.services.cloudformation.model.Stack;
+import software.amazon.awssdk.services.s3vectors.S3VectorsClient;
+import software.amazon.awssdk.services.s3vectors.model.Index;
+import software.amazon.awssdk.services.s3vectors.model.IndexSummary;
+import software.amazon.awssdk.services.s3vectors.model.NotFoundException;
+import software.amazon.awssdk.services.s3vectors.model.PutInputVector;
+import software.amazon.awssdk.services.s3vectors.model.VectorBucket;
+import software.amazon.awssdk.services.s3vectors.model.VectorData;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+@DisplayName("CloudFormation S3 Vectors resources")
+class CloudFormationS3VectorsTest {
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+ private static final String TEMPLATE = """
+ {
+ "Parameters":{"Tag":{"Type":"String"},"Dimension":{"Type":"Number"}},
+ "Resources":{
+ "Bucket":{"Type":"AWS::S3Vectors::VectorBucket","Properties":{
+ "EncryptionConfiguration":{"SseType":"AES256"},
+ "Tags":[{"Key":"version","Value":{"Ref":"Tag"}}]}},
+ "Index":{"Type":"AWS::S3Vectors::Index","Properties":{
+ "VectorBucketArn":{"Ref":"Bucket"},"DataType":"float32",
+ "Dimension":{"Ref":"Dimension"},"DistanceMetric":"cosine",
+ "MetadataConfiguration":{"NonFilterableMetadataKeys":["text"]},
+ "Tags":[{"Key":"version","Value":{"Ref":"Tag"}}]}}
+ },
+ "Outputs":{
+ "BucketRef":{"Value":{"Ref":"Bucket"}},
+ "BucketArn":{"Value":{"Fn::GetAtt":["Bucket","VectorBucketArn"]}},
+ "BucketCreated":{"Value":{"Fn::GetAtt":["Bucket","CreationTime"]}},
+ "IndexRef":{"Value":{"Ref":"Index"}},
+ "IndexArn":{"Value":{"Fn::GetAtt":["Index","IndexArn"]}},
+ "IndexCreated":{"Value":{"Fn::GetAtt":["Index","CreationTime"]}}
+ }
+ }
+ """;
+
+ @ParameterizedTest
+ @ValueSource(strings = {"us-east-1", "us-gov-west-1"})
+ void sdkStackLifecyclePreservesDataOnTagUpdatesAndReplacesImmutableIndexes(String region) throws Exception {
+ String stackName = "cfn-vectors-" + UUID.randomUUID().toString().substring(0, 8);
+ try (CloudFormationClient cfn = cloudFormation(region); S3VectorsClient vectors = vectors(region)) {
+ try {
+ cfn.createStack(request -> request.stackName(stackName).templateBody(TEMPLATE)
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "3")));
+ Stack created = awaitStack(cfn, stackName, "CREATE_COMPLETE");
+ Map<String, String> outputs = outputs(created);
+ assertThat(outputs.get("BucketArn")).isEqualTo(outputs.get("BucketRef"));
+ assertThat(outputs.get("IndexArn")).isEqualTo(outputs.get("IndexRef"));
+ String partition = region.startsWith("us-gov-") ? "aws-us-gov" : "aws";
+ assertThat(outputs.get("BucketArn")).startsWith("arn:" + partition + ":s3vectors:" + region + ":");
+ String bucketName = leaf(outputs.get("BucketArn"));
+ String indexName = leaf(outputs.get("IndexArn"));
+ VectorBucket bucket = vectors.getVectorBucket(request -> request.vectorBucketName(bucketName)).vectorBucket();
+ Index index = vectors.getIndex(request -> request.vectorBucketName(bucketName).indexName(indexName)).index();
+ assertThat(bucket.vectorBucketArn()).isEqualTo(outputs.get("BucketArn"));
+ assertThat(index.indexArn()).isEqualTo(outputs.get("IndexArn"));
+ assertThat(bucket.creationTime().toEpochMilli()).isEqualTo(Instant.parse(outputs.get("BucketCreated")).toEpochMilli());
+ assertThat(index.creationTime().toEpochMilli()).isEqualTo(Instant.parse(outputs.get("IndexCreated")).toEpochMilli());
+ assertThat(index.encryptionConfiguration().sseTypeAsString()).isEqualTo("AES256");
+ assertThat(index.metadataConfiguration().nonFilterableMetadataKeys()).containsExactly("text");
+ vectors.putVectors(request -> request.vectorBucketName(bucketName).indexName(indexName)
+ .vectors(PutInputVector.builder().key("vector")
+ .data(VectorData.builder().float32(1.0f, 0.0f, 0.0f).build()).build()));
+
+ cfn.updateStack(request -> request.stackName(stackName).templateBody(TEMPLATE)
+ .parameters(parameter("Tag", "second"), parameter("Dimension", "3")));
+ assertThat(outputs(awaitStack(cfn, stackName, "UPDATE_COMPLETE"))).isEqualTo(outputs);
+ assertThat(vectors.getVectors(request -> request.vectorBucketName(bucketName)
+ .indexName(indexName).keys("vector")).vectors()).hasSize(1);
+
+ cfn.updateStack(request -> request.stackName(stackName).templateBody(TEMPLATE)
+ .parameters(parameter("Tag", "second"), parameter("Dimension", "4")));
+ Map<String, String> replaced = outputs(awaitStack(cfn, stackName, "UPDATE_COMPLETE"));
+ assertThat(replaced.get("BucketArn")).isEqualTo(outputs.get("BucketArn"));
+ assertThat(replaced.get("IndexArn")).isNotEqualTo(outputs.get("IndexArn"));
+ assertThat(vectors.getIndex(request -> request.vectorBucketName(bucketName)
+ .indexName(leaf(replaced.get("IndexArn")))).index().dimension()).isEqualTo(4);
+ assertThatThrownBy(() -> vectors.getIndex(request -> request.vectorBucketName(bucketName).indexName(indexName)))
+ .isInstanceOf(NotFoundException.class);
+
+ cfn.deleteStack(request -> request.stackName(stackName));
+ awaitDeleted(cfn, stackName);
+ assertThatThrownBy(() -> vectors.getVectorBucket(request -> request.vectorBucketName(bucketName)))
+ .isInstanceOf(NotFoundException.class);
+ } finally {
+ cfn.deleteStack(request -> request.stackName(stackName));
+ awaitDeleted(cfn, stackName);
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void tagUpdateAfterReplacementRollbackPreservesIndexAndVectors(boolean named) throws Exception {
+ String name = TestFixtures.uniqueName("cfn-vectors-rollback");
+ ObjectNode original = (ObjectNode) MAPPER.readTree(TEMPLATE);
+ if (named) {
+ ((ObjectNode) original.path("Resources").path("Index").path("Properties"))
+ .put("IndexName", "original-index");
+ }
+ ObjectNode replacement = original.deepCopy();
+ ObjectNode resources = (ObjectNode) replacement.path("Resources");
+ if (named) {
+ ((ObjectNode) resources.path("Index").path("Properties")).put("IndexName", "replacement-index");
+ }
+ ObjectNode invalid = resources.putObject("Broken").put("Type", "AWS::S3Vectors::Index")
+ .put("DependsOn", "Index").putObject("Properties");
+ invalid.putObject("VectorBucketArn").put("Ref", "Bucket");
+ invalid.put("Dimension", 3).put("DataType", "float64").put("DistanceMetric", "cosine");
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient();
+ S3VectorsClient vectors = TestFixtures.s3vectorsClient()) {
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(original.toString())
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "3")));
+ Map<String, String> before = outputs(awaitStack(cfn, name, "CREATE_COMPLETE"));
+ String bucketName = leaf(before.get("BucketArn"));
+ String indexName = leaf(before.get("IndexArn"));
+ vectors.putVectors(request -> request.vectorBucketName(bucketName).indexName(indexName)
+ .vectors(PutInputVector.builder().key("vector")
+ .data(VectorData.builder().float32(1.0f, 0.0f, 0.0f).build()).build()));
+
+ cfn.updateStack(request -> request.stackName(name).templateBody(replacement.toString())
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "4")));
+ assertThat(outputs(awaitStack(cfn, name, "UPDATE_ROLLBACK_COMPLETE"))).isEqualTo(before);
+ String replacementArn = cfn.describeStackEvents(request -> request.stackName(name)).stackEvents()
+ .stream().filter(event -> "Index".equals(event.logicalResourceId())
+ && "UPDATE_COMPLETE".equals(event.resourceStatusAsString())
+ && !before.get("IndexArn").equals(event.physicalResourceId()))
+ .findFirst().orElseThrow().physicalResourceId();
+ assertThatThrownBy(() -> vectors.getIndex(request -> request.vectorBucketName(bucketName)
+ .indexName(leaf(replacementArn)))).isInstanceOf(NotFoundException.class);
+
+ cfn.updateStack(request -> request.stackName(name).templateBody(original.toString())
+ .parameters(parameter("Tag", "second"), parameter("Dimension", "3")));
+ assertThat(outputs(awaitStack(cfn, name, "UPDATE_COMPLETE"))).isEqualTo(before);
+ assertThat(vectors.getIndex(request -> request.vectorBucketName(bucketName).indexName(indexName))
+ .index().dimension()).isEqualTo(3);
+ assertThat(vectors.getVectors(request -> request.vectorBucketName(bucketName)
+ .indexName(indexName).keys("vector")).vectors())
+ .extracting(vector -> vector.key()).containsExactly("vector");
+ assertThat(vectors.listIndexes(request -> request.vectorBucketName(bucketName)).indexes())
+ .extracting(index -> index.indexArn()).containsExactly(before.get("IndexArn"));
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"VectorBucketName", "VectorBucketArn"})
+ void namedResourcesCanReferenceAnExistingBucketAndTolerateExternalDeletion(String selector) throws Exception {
+ String bucketName = "cfn-existing-" + UUID.randomUUID().toString().substring(0, 8);
+ String stackName = bucketName + "-stack";
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient(); S3VectorsClient vectors = TestFixtures.s3vectorsClient()) {
+ String bucketArn = vectors.createVectorBucket(request -> request.vectorBucketName(bucketName)).vectorBucketArn();
+ String template = """
+ {"Resources":{"Index":{"Type":"AWS::S3Vectors::Index","Properties":{
+ "%s":"%s","IndexName":"named-index","Dimension":3,"DataType":"float32","DistanceMetric":"euclidean"}}},
+ "Outputs":{"Arn":{"Value":{"Ref":"Index"}}}}
+ """.formatted(selector, "VectorBucketName".equals(selector) ? bucketName : bucketArn);
+ try {
+ cfn.createStack(request -> request.stackName(stackName).templateBody(template));
+ assertThat(outputs(awaitStack(cfn, stackName, "CREATE_COMPLETE")).get("Arn")).isEqualTo(bucketArn + "/index/named-index");
+ vectors.deleteIndex(request -> request.vectorBucketName(bucketName).indexName("named-index"));
+ cfn.deleteStack(request -> request.stackName(stackName));
+ awaitDeleted(cfn, stackName);
+ } finally {
+ cfn.deleteStack(request -> request.stackName(stackName));
+ awaitDeleted(cfn, stackName);
+ vectors.deleteVectorBucket(request -> request.vectorBucketName(bucketName));
+ }
+ }
+ }
+
+ static Stream<Arguments> invalidIndexSettings() {
+ return Stream.of(
+ Arguments.of("float64", "cosine", List.of(), "dataType"),
+ Arguments.of("float32", "manhattan", List.of(), "distanceMetric"),
+ Arguments.of("float32", "cosine", List.of(""), "NonFilterableMetadataKeys"),
+ Arguments.of("float32", "cosine", List.of(" "), "NonFilterableMetadataKeys"),
+ Arguments.of("float32", "cosine", Collections.singletonList(null), "NonFilterableMetadataKeys"),
+ Arguments.of("float32", "cosine", List.of("a".repeat(64)), "NonFilterableMetadataKeys"),
+ Arguments.of("float32", "cosine", Collections.nCopies(11, "key"), "NonFilterableMetadataKeys"));
+ }
+
+ static Stream<Arguments> invalidEncryptionSettings() {
+ return Stream.of("VectorBucket", "Index").flatMap(type -> Stream.of(
+ Arguments.of(type, "\"AES256\"", "EncryptionConfiguration"),
+ Arguments.of(type, "[]", "EncryptionConfiguration"),
+ Arguments.of(type, "{\"SseType\":\"aws:kms\",\"KmsKeyArn\":\"key\"}", "KmsKeyArn")));
+ }
+
+ @ParameterizedTest
+ @MethodSource("invalidEncryptionSettings")
+ void invalidEncryptionSettingsFailThroughCloudFormation(String type, String configuration,
+ String errorMember) throws Exception {
+ String name = "invalid-encryption-" + UUID.randomUUID().toString().substring(0, 8);
+ boolean index = "Index".equals(type);
+ ObjectNode props = MAPPER.createObjectNode().put("VectorBucketName", name);
+ props.set("EncryptionConfiguration", MAPPER.readTree(configuration));
+ if (index) {
+ props.put("IndexName", "index").put("Dimension", 3)
+ .put("DataType", "float32").put("DistanceMetric", "cosine");
+ }
+ String template = MAPPER.writeValueAsString(Map.of("Resources", Map.of("Vectors", Map.of(
+ "Type", "AWS::S3Vectors::" + type, "Properties", props))));
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient(); S3VectorsClient vectors = TestFixtures.s3vectorsClient()) {
+ if (index) {
+ vectors.createVectorBucket(request -> request.vectorBucketName(name));
+ }
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(template));
+ awaitStack(cfn, name, "ROLLBACK_COMPLETE");
+ assertThat(cfn.describeStackEvents(request -> request.stackName(name)).stackEvents().stream()
+ .anyMatch(event -> "Vectors".equals(event.logicalResourceId())
+ && "CREATE_FAILED".equals(event.resourceStatusAsString())
+ && event.resourceStatusReason().contains(errorMember))).isTrue();
+ if (index) {
+ assertThat(vectors.listIndexes(request -> request.vectorBucketName(name)).indexes()).isEmpty();
+ } else {
+ assertThatThrownBy(() -> vectors.getVectorBucket(request -> request.vectorBucketName(name)))
+ .isInstanceOf(NotFoundException.class);
+ }
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ if (index) {
+ vectors.deleteVectorBucket(request -> request.vectorBucketName(name));
+ }
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"us-east-1", "us-gov-west-1"})
+ void kmsEncryptionResolvesIntrinsicsAndIsRetainedForBothResourceTypes(String region) throws Exception {
+ String name = "kms-vectors-" + UUID.randomUUID().toString().substring(0, 8);
+ ObjectNode template = (ObjectNode) MAPPER.readTree(TEMPLATE);
+ ObjectNode configuration = MAPPER.createObjectNode().put("SseType", "aws:kms");
+ configuration.putObject("KmsKeyArn").put("Fn::Sub",
+ "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1234abcd-12ab-34cd-56ef-1234567890ab");
+ for (String logicalId : List.of("Bucket", "Index")) {
+ ((ObjectNode) template.path("Resources").path(logicalId).path("Properties"))
+ .set("EncryptionConfiguration", configuration);
+ }
+ try (CloudFormationClient cfn = cloudFormation(region); S3VectorsClient vectors = vectors(region)) {
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(template.toString())
+ .parameters(parameter("Tag", "kms"), parameter("Dimension", "3")));
+ Map<String, String> outputs = outputs(awaitStack(cfn, name, "CREATE_COMPLETE"));
+ String bucketName = leaf(outputs.get("BucketArn"));
+ VectorBucket bucket = vectors.getVectorBucket(request -> request.vectorBucketName(bucketName))
+ .vectorBucket();
+ Index index = vectors.getIndex(request -> request.vectorBucketName(bucketName)
+ .indexName(leaf(outputs.get("IndexArn")))).index();
+ String key = outputs.get("BucketArn").split(":bucket/")[0].replace(":s3vectors:", ":kms:")
+ + ":key/1234abcd-12ab-34cd-56ef-1234567890ab";
+ assertThat(bucket.encryptionConfiguration().sseTypeAsString()).isEqualTo("aws:kms");
+ assertThat(bucket.encryptionConfiguration().kmsKeyArn()).isEqualTo(key);
+ assertThat(index.encryptionConfiguration().sseTypeAsString()).isEqualTo("aws:kms");
+ assertThat(index.encryptionConfiguration().kmsKeyArn()).isEqualTo(key);
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @MethodSource("invalidIndexSettings")
+ void invalidIndexSettingsFailThroughCloudFormation(String dataType, String distanceMetric,
+ List<String> keys, String errorMember) throws Exception {
+ String name = "invalid-vectors-" + UUID.randomUUID().toString().substring(0, 8);
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient(); S3VectorsClient vectors = TestFixtures.s3vectorsClient()) {
+ vectors.createVectorBucket(request -> request.vectorBucketName(name));
+ try {
+ String template = MAPPER.writeValueAsString(Map.of("Resources", Map.of("Index", Map.of(
+ "Type", "AWS::S3Vectors::Index", "Properties", Map.of(
+ "VectorBucketName", name, "IndexName", "index", "Dimension", 3,
+ "DataType", dataType, "DistanceMetric", distanceMetric,
+ "MetadataConfiguration", Map.of("NonFilterableMetadataKeys", keys))))));
+ cfn.createStack(request -> request.stackName(name).templateBody(template));
+ awaitStack(cfn, name, "ROLLBACK_COMPLETE");
+ assertThat(cfn.describeStackEvents(request -> request.stackName(name)).stackEvents().stream()
+ .anyMatch(event -> "Index".equals(event.logicalResourceId())
+ && "CREATE_FAILED".equals(event.resourceStatusAsString())
+ && event.resourceStatusReason().contains(errorMember))).isTrue();
+ assertThat(vectors.listIndexes(request -> request.vectorBucketName(name)).indexes()).isEmpty();
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ for (IndexSummary index : vectors.listIndexes(request -> request.vectorBucketName(name)).indexes()) {
+ vectors.deleteIndex(request -> request.vectorBucketName(name).indexName(index.indexName()));
+ }
+ vectors.deleteVectorBucket(request -> request.vectorBucketName(name));
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void legacyStubStacksUpgradeToRealResources(boolean named) throws Exception {
+ String name = "upgrade-vectors-" + UUID.randomUUID().toString().substring(0, 8);
+ ObjectNode template = (ObjectNode) MAPPER.readTree(TEMPLATE);
+ if (named) {
+ ((ObjectNode) template.path("Resources").path("Bucket").path("Properties")).put("VectorBucketName", name);
+ ((ObjectNode) template.path("Resources").path("Index").path("Properties")).put("IndexName", "index");
+ }
+ String realTemplate = template.toString();
+ String stubTemplate = realTemplate.replace("AWS::S3Vectors::VectorBucket", "AWS::Unsupported::VectorBucket")
+ .replace("AWS::S3Vectors::Index", "AWS::Unsupported::Index");
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient(); S3VectorsClient vectors = TestFixtures.s3vectorsClient()) {
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(stubTemplate)
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "3")));
+ Map<String, String> before = outputs(awaitStack(cfn, name, "CREATE_COMPLETE"));
+ assertThat(before.get("BucketRef").matches("Bucket-[0-9a-f]{8}")).isTrue();
+ assertThat(before.get("IndexRef").matches("Index-[0-9a-f]{8}")).isTrue();
+
+ cfn.updateStack(request -> request.stackName(name).templateBody(realTemplate)
+ .parameters(parameter("Tag", "second"), parameter("Dimension", "3")));
+ Map<String, String> after = outputs(awaitStack(cfn, name, "UPDATE_COMPLETE"));
+ assertThat(after.get("BucketRef")).isNotEqualTo(before.get("BucketRef"));
+ assertThat(after.get("BucketArn")).isEqualTo(after.get("BucketRef"));
+ assertThat(after.get("IndexArn")).isEqualTo(after.get("IndexRef"));
+ String bucketName = leaf(after.get("BucketArn"));
+ Index index = vectors.getIndex(request -> request.vectorBucketName(bucketName)
+ .indexName(leaf(after.get("IndexArn")))).index();
+ assertThat(index.indexArn()).isEqualTo(after.get("IndexArn"));
+ assertThat(index.creationTime().toEpochMilli()).isEqualTo(Instant.parse(after.get("IndexCreated")).toEpochMilli());
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ assertThatThrownBy(() -> vectors.getVectorBucket(request -> request.vectorBucketName(bucketName)))
+ .isInstanceOf(NotFoundException.class);
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ }
+ }
+ }
+
+ static Stream<Arguments> changeSetProperties() {
+ return Stream.of(
+ Arguments.of("Index", "Dimension", "4", "True"),
+ Arguments.of("Bucket", "EncryptionConfiguration", """
+ {"SseType":"aws:kms","KmsKeyArn":{"Fn::Sub":
+ "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1234abcd-12ab-34cd-56ef-1234567890ab"}}
+ """, "True"),
+ Arguments.of("Bucket", "Tags", "[{\"Key\":\"version\",\"Value\":\"second\"}]", "False"),
+ Arguments.of("Index", "Tags", "[{\"Key\":\"version\",\"Value\":\"second\"}]", "False"));
+ }
+
+ @ParameterizedTest
+ @MethodSource("changeSetProperties")
+ void changeSetsReportReplacementForImmutableProperties(String logicalId, String property,
+ String value, String replacement) throws Exception {
+ String name = TestFixtures.uniqueName("cfn-vectors-change-set");
+ ObjectNode template = (ObjectNode) MAPPER.readTree(TEMPLATE);
+ ((ObjectNode) template.path("Resources").path(logicalId).path("Properties"))
+ .set(property, MAPPER.readTree(value));
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient()) {
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(TEMPLATE)
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "3")));
+ awaitStack(cfn, name, "CREATE_COMPLETE");
+ String changeSet = cfn.createChangeSet(request -> request.stackName(name).changeSetName("update")
+ .changeSetType(ChangeSetType.UPDATE).templateBody(template.toString())
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "3"))).id();
+ TestFixtures.await(() -> {
+ DescribeChangeSetResponse response = cfn.describeChangeSet(request -> request.changeSetName(changeSet));
+ assertThat(response.statusAsString()).as(response.statusReason()).isNotEqualTo("FAILED");
+ return "CREATE_COMPLETE".equals(response.statusAsString());
+ }, changeSet, "CREATE_COMPLETE", Duration.ofSeconds(60).toNanos(), 100);
+ ResourceChange change = cfn.describeChangeSet(request -> request.changeSetName(changeSet)).changes()
+ .stream().map(item -> item.resourceChange())
+ .filter(item -> logicalId.equals(item.logicalResourceId())).findFirst().orElseThrow();
+ assertThat(change.actionAsString()).isEqualTo("Modify");
+ assertThat(change.replacementAsString()).isEqualTo(replacement);
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"absent", "null", "{}", "{\"SseType\":null}", "{\"SseType\":\"AES256\"}"})
+ void indexesInheritBucketEncryptionUnlessExplicitlyOverridden(String configuration) throws Exception {
+ String name = TestFixtures.uniqueName("cfn-vectors-inherit");
+ ObjectNode template = (ObjectNode) MAPPER.readTree(TEMPLATE);
+ ObjectNode bucketProps = (ObjectNode) template.path("Resources").path("Bucket").path("Properties");
+ ObjectNode encryption = bucketProps.putObject("EncryptionConfiguration").put("SseType", "aws:kms");
+ encryption.putObject("KmsKeyArn").put("Fn::Sub",
+ "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1234abcd-12ab-34cd-56ef-1234567890ab");
+ if (!"absent".equals(configuration)) {
+ ((ObjectNode) template.path("Resources").path("Index").path("Properties"))
+ .set("EncryptionConfiguration", MAPPER.readTree(configuration));
+ }
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient();
+ S3VectorsClient vectors = TestFixtures.s3vectorsClient()) {
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(template.toString())
+ .parameters(parameter("Tag", "kms"), parameter("Dimension", "3")));
+ Map<String, String> outputs = outputs(awaitStack(cfn, name, "CREATE_COMPLETE"));
+ String bucketName = leaf(outputs.get("BucketArn"));
+ VectorBucket bucket = vectors.getVectorBucket(request -> request.vectorBucketName(bucketName)).vectorBucket();
+ Index index = vectors.getIndex(request -> request.vectorBucketName(bucketName)
+ .indexName(leaf(outputs.get("IndexArn")))).index();
+ assertThat(bucket.encryptionConfiguration().sseTypeAsString()).isEqualTo("aws:kms");
+ if (configuration.contains("AES256")) {
+ assertThat(index.encryptionConfiguration().sseTypeAsString()).isEqualTo("AES256");
+ assertThat(index.encryptionConfiguration().kmsKeyArn()).isNull();
+ } else {
+ assertThat(index.encryptionConfiguration()).isEqualTo(bucket.encryptionConfiguration());
+ }
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ }
+ }
+ }
+
+ @Test
+ void propertySnapshotsAreNotExposedThroughGetAtt() throws Exception {
+ String name = TestFixtures.uniqueName("cfn-vectors-private");
+ ObjectNode template = (ObjectNode) MAPPER.readTree(TEMPLATE);
+ ObjectNode outputs = (ObjectNode) template.path("Outputs");
+ for (String logicalId : List.of("Bucket", "Index")) {
+ for (String key : List.of("FlociS3VectorsProperties", "__FlociS3VectorsProperties")) {
+ String output = logicalId + (key.startsWith("__") ? "Private" : "Legacy");
+ outputs.putObject(output).putObject("Value")
+ .putArray("Fn::GetAtt").add(logicalId).add(key);
+ }
+ }
+ try (CloudFormationClient cfn = TestFixtures.cloudFormationClient()) {
+ try {
+ cfn.createStack(request -> request.stackName(name).templateBody(template.toString())
+ .parameters(parameter("Tag", "first"), parameter("Dimension", "3")));
+ Map<String, String> values = outputs(awaitStack(cfn, name, "CREATE_COMPLETE"));
+ for (String logicalId : List.of("Bucket", "Index")) {
+ assertThat(values.get(logicalId + "Private"))
+ .isEqualTo(logicalId + ".__FlociS3VectorsProperties");
+ assertThat(values.get(logicalId + "Legacy"))
+ .isEqualTo(logicalId + ".FlociS3VectorsProperties");
+ }
+ } finally {
+ cfn.deleteStack(request -> request.stackName(name));
+ awaitDeleted(cfn, name);
+ }
+ }
+ }
+
+ private CloudFormationClient cloudFormation(String region) {
+ return CloudFormationClient.builder().endpointOverride(TestFixtures.endpoint()).region(Region.of(region))
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
+ .build();
+ }
+
+ private S3VectorsClient vectors(String region) {
+ return S3VectorsClient.builder().endpointOverride(TestFixtures.endpoint()).region(Region.of(region))
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
+ .build();
+ }
+
+ private static Parameter parameter(String name, String value) {
+ return Parameter.builder().parameterKey(name).parameterValue(value).build();
+ }
+
+ private static Stack awaitStack(CloudFormationClient client, String name, String status) throws InterruptedException {
+ TestFixtures.await(() -> {
+ Stack stack = client.describeStacks(request -> request.stackName(name)).stacks().get(0);
+ String actual = stack.stackStatusAsString();
+ if (!status.equals(actual) && (actual.endsWith("_FAILED") || actual.endsWith("ROLLBACK_COMPLETE"))) {
+ throw new AssertionError(name + " reached " + actual + ": " + stack.stackStatusReason());
+ }
+ return status.equals(actual);
+ }, name, status, Duration.ofSeconds(60).toNanos(), 100);
+ return client.describeStacks(request -> request.stackName(name)).stacks().get(0);
+ }
+
+ private static void awaitDeleted(CloudFormationClient client, String name) throws InterruptedException {
+ TestFixtures.await(() -> {
+ try {
+ client.describeStacks(request -> request.stackName(name));
+ return false;
+ } catch (CloudFormationException error) {
+ if (!error.getMessage().contains("does not exist")) {
+ throw error;
+ }
+ return true;
+ }
+ }, name, "deleted", Duration.ofSeconds(60).toNanos(), 100);
+ }
+
+ private static Map<String, String> outputs(Stack stack) {
+ return stack.outputs().stream().collect(Collectors.toMap(Output::outputKey, Output::outputValue));
+ }
+
+ private static String leaf(String arn) {
+ return arn.substring(arn.lastIndexOf('/') + 1);
+ }
+}
diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md
index da22344b85..d2025de9a8 100644
--- a/docs/services/cloudformation.md
+++ b/docs/services/cloudformation.md
@@ -170,6 +170,7 @@ cross-resource references.
| Service | Resource types |
|---|---|
| S3 | `Bucket`, `BucketPolicy` (document stored on the bucket; S3 does not evaluate it) |
+| S3 Vectors | `VectorBucket`, `Index` |
| SQS | `Queue`, `QueuePolicy` (accepted; policy not enforced) |
| SNS | `Topic`, `Subscription`, `TopicPolicy` |
| SES | `EmailIdentity` (BYODKIM is not supported by this resource; Easy DKIM DNS attributes use the shared emulator signing zone `dkim.amazonses.com` rather than AWS's region- and identity-specific zone assignment) |
diff --git a/docs/services/s3vectors.md b/docs/services/s3vectors.md
index 8281dc691d..50ed73f9f3 100644
--- a/docs/services/s3vectors.md
+++ b/docs/services/s3vectors.md
@@ -69,8 +69,41 @@ Index dimensions must be between 1 and 4096. Metadata configuration accepts up t
10 unique non-filterable keys, each a non-blank string of 1 to 63 characters.
Queries reject filters on these keys, including filters nested in logical expressions.
-Writes to the same bucket are serialized across indexes, vectors, and bucket
+Writes to the same bucket are serialized across tags, indexes, vectors, and bucket
deletion so concurrent changes do not overwrite each other or restore deleted data.
Encryption settings are stored and returned; Floci does not perform KMS encryption.
Standalone S3 Vectors tagging APIs are not implemented.
+
+## CloudFormation
+
+`AWS::S3Vectors::VectorBucket` and `AWS::S3Vectors::Index` create real S3 Vectors
+resources. Both return their ARN from `Ref` and expose `CreationTime` through
+`Fn::GetAtt`. The ARN attributes are `VectorBucketArn` and `IndexArn`, respectively.
+An index accepts either `VectorBucketName` or `VectorBucketArn`.
+
+```yaml
+Resources:
+ Vectors:
+ Type: AWS::S3Vectors::VectorBucket
+ Properties:
+ EncryptionConfiguration:
+ SseType: AES256
+ Embeddings:
+ Type: AWS::S3Vectors::Index
+ Properties:
+ VectorBucketArn: !Ref Vectors
+ DataType: float32
+ Dimension: 3
+ DistanceMetric: cosine
+ MetadataConfiguration:
+ NonFilterableMetadataKeys: [text]
+```
+
+Omitted names are generated in lowercase. Tag changes preserve resource identity
+and vector data, including removing tags dropped from the template. Other property
+changes replace the resource; a custom-named resource needs a different name when
+replacement would otherwise reuse its existing identity. Replacement cleanup and
+rollback use the normal CloudFormation lifecycle and honor `UpdateReplacePolicy`.
+Stack deletion removes indexes before their bucket. A bucket containing indexes
+outside the stack causes deletion to fail.
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3VectorsCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3VectorsCfnProvisioner.java
new file mode 100644
index 0000000000..e30c77b903
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3VectorsCfnProvisioner.java
@@ -0,0 +1,309 @@
+package io.github.hectorvent.floci.services.cloudformation.provisioners;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.AwsRegions;
+import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
+import io.github.hectorvent.floci.services.s3vectors.S3VectorsService;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorBucket;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorIndex;
+import jakarta.enterprise.context.ApplicationScoped;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+@ApplicationScoped
+public class S3VectorsCfnProvisioner implements CfnResourceProvisioner {
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+ private static final String PROPERTIES = "__FlociS3VectorsProperties";
+ private static final String PROPERTIES_PRIOR = "__FlociS3VectorsPropertiesBeforeUpdate";
+ private static final String TAG_SNAPSHOT = "__FlociS3VectorsTagsBeforeUpdate";
+ private static final Pattern KMS_KEY_ARN = Pattern.compile(
+ "arn:" + AwsArnUtils.PARTITION_REGEX + ":kms:[-a-z0-9]*:[0-9]{12}:key/.+");
+
+ private final S3VectorsService service;
+
+ public S3VectorsCfnProvisioner(S3VectorsService service) {
+ this.service = service;
+ }
+
+ @Override
+ public Set<String> resourceTypes() {
+ return Set.of("AWS::S3Vectors::VectorBucket", "AWS::S3Vectors::Index");
+ }
+
+ @Override
+ public void provision(StackResource resource, JsonNode props, ProvisionContext ctx) {
+ ObjectNode resolved = props == null ? MAPPER.createObjectNode()
+ : (ObjectNode) ctx.engine().resolveNode(props);
+ ObjectNode immutable = resolved.deepCopy();
+ immutable.remove("Tags");
+ Map<String, String> before = new HashMap<>(resource.getAttributes());
+ boolean updatesEntity = ctx.isUpdate() && !CfnResourceDispatcher.isStub(ctx.priorPhysicalId(), before);
+ boolean reuse = updatesEntity && immutable.equals(readProperties(resource));
+ Map<String, String> tags = ctx.resolveTags(resolved, "Tags");
+ switch (resource.getResourceType()) {
+ case "AWS::S3Vectors::VectorBucket" -> provisionBucket(resource, resolved, tags, reuse, updatesEntity, ctx);
+ case "AWS::S3Vectors::Index" -> provisionIndex(resource, resolved, tags, reuse, updatesEntity, ctx);
+ default -> throw new IllegalStateException("Unsupported S3 Vectors type: " + resource.getResourceType());
+ }
+ resource.getAttributes().put(PROPERTIES, immutable.toString());
+ ReplacementCleanup.record(resource, ctx, before);
+ if (ctx.isUpdate() && !ctx.priorPhysicalId().equals(resource.getPhysicalId())) {
+ resource.getAttributes().put(PROPERTIES_PRIOR, before.getOrDefault(PROPERTIES, ""));
+ }
+ }
+
+ private void provisionBucket(StackResource resource, JsonNode props, Map<String, String> tags,
+ boolean reuse, boolean updatesEntity, ProvisionContext ctx) {
+ VectorBucket bucket;
+ if (reuse) {
+ String name = arnParts(ctx.priorPhysicalId(), false)[1];
+ bucket = service.getVectorBucket(name, ctx.region());
+ snapshotTags(resource, bucket.getTags());
+ service.replaceBucketTags(name, tags, ctx.region());
+ } else {
+ String name = physicalName(props, "VectorBucketName", resource, ctx, false);
+ rejectSameNameReplacement(ctx, updatesEntity, "bucket/" + name);
+ bucket = service.createVectorBucket(name, encryption(props, ctx, "AES256"), tags, ctx.region());
+ }
+ resource.setPhysicalId(bucket.getVectorBucketArn());
+ resource.getAttributes().put("VectorBucketArn", bucket.getVectorBucketArn());
+ resource.getAttributes().put("CreationTime", bucket.getCreationTime().toString());
+ }
+
+ private void provisionIndex(StackResource resource, JsonNode props, Map<String, String> tags,
+ boolean reuse, boolean updatesEntity, ProvisionContext ctx) {
+ String bucketName = bucketName(props, ctx);
+ String dataType = required(props, "DataType", ctx);
+ String distanceMetric = required(props, "DistanceMetric", ctx);
+ int dimension;
+ try {
+ dimension = Integer.parseInt(required(props, "Dimension", ctx));
+ } catch (NumberFormatException e) {
+ throw validation("Dimension must be an integer between 1 and 4096.");
+ }
+ VectorIndex index;
+ if (reuse) {
+ String name = arnParts(ctx.priorPhysicalId(), true)[3];
+ index = service.getIndex(bucketName, name, ctx.region());
+ snapshotTags(resource, index.getTags());
+ service.replaceIndexTags(bucketName, name, tags, ctx.region());
+ } else {
+ String name = physicalName(props, "IndexName", resource, ctx, true);
+ rejectSameNameReplacement(ctx, updatesEntity, "bucket/" + bucketName + "/index/" + name);
+ JsonNode metadataKeys = props.path("MetadataConfiguration").path("NonFilterableMetadataKeys");
+ List<String> keys = new ArrayList<>();
+ if (!metadataKeys.isMissingNode()) {
+ if (!metadataKeys.isArray()) {
+ throw validation("NonFilterableMetadataKeys must be a list of strings.");
+ }
+ for (JsonNode key : metadataKeys) {
+ keys.add(key.isTextual() ? key.textValue() : null);
+ }
+ }
+ index = service.createIndex(bucketName, name, dimension, dataType, distanceMetric,
+ keys, encryption(props, ctx, null), tags, ctx.region());
+ }
+ resource.setPhysicalId(index.getIndexArn());
+ resource.getAttributes().put("IndexArn", index.getIndexArn());
+ resource.getAttributes().put("CreationTime", index.getCreationTime().toString());
+ }
+
+ private static String physicalName(JsonNode props, String property, StackResource resource,
+ ProvisionContext ctx, boolean index) {
+ String name = ctx.resolveOptional(props, property);
+ if (name == null) {
+ return ctx.generatePhysicalName(resource.getLogicalId(), 63, true);
+ }
+ return validateName(name, property, index);
+ }
+
+ private static String validateName(String name, String property, boolean index) {
+ String pattern = index ? "[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]" : "[a-z0-9][a-z0-9-]{1,61}[a-z0-9]";
+ if (!name.matches(pattern)) {
+ throw validation(property + " must be a valid lowercase name of 3 to 63 characters.");
+ }
+ return name;
+ }
+
+ private static void rejectSameNameReplacement(ProvisionContext ctx, boolean updatesEntity, String resourcePath) {
+ if (updatesEntity && AwsArnUtils.parse(ctx.priorPhysicalId()).resource().equals(resourcePath)) {
+ throw validation("Updating this custom-named S3 Vectors resource requires replacement. Specify a new name.");
+ }
+ }
+
+ private static String bucketName(JsonNode props, ProvisionContext ctx) {
+ String name = ctx.resolveOptional(props, "VectorBucketName");
+ String arn = ctx.resolveOptional(props, "VectorBucketArn");
+ if ((name == null) == (arn == null)) {
+ throw validation("Specify exactly one of VectorBucketName or VectorBucketArn.");
+ }
+ if (arn == null) {
+ return validateName(name, "VectorBucketName", false);
+ }
+ String[] parts = arnParts(arn, false);
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ if (!ctx.region().equals(parsed.region()) || !ctx.accountId().equals(parsed.accountId())
+ || !AwsRegions.partitionFor(ctx.region()).equals(parsed.partition())) {
+ throw validation("VectorBucketArn must belong to the stack's region and account.");
+ }
+ return validateName(parts[1], "VectorBucketArn bucket name", false);
+ }
+
+ private static String[] arnParts(String arn, boolean index) {
+ try {
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ String[] parts = parsed.resource().split("/", -1);
+ if (!"s3vectors".equals(parsed.service()) || parts.length != (index ? 4 : 2)
+ || !"bucket".equals(parts[0]) || parts[1].isBlank()
+ || (index && (!"index".equals(parts[2]) || parts[3].isBlank()))) {
+ throw validation("Invalid S3 Vectors ARN: " + arn);
+ }
+ return parts;
+ } catch (IllegalArgumentException e) {
+ throw validation("Invalid S3 Vectors ARN: " + arn);
+ }
+ }
+
+ private static Object encryption(JsonNode props, ProvisionContext ctx, String defaultType) {
+ JsonNode config = props.path("EncryptionConfiguration");
+ if (config.isMissingNode() || config.isNull()) {
+ return null;
+ }
+ if (!config.isObject()) {
+ throw validation("EncryptionConfiguration must be an object.");
+ }
+ String type = ctx.resolveOrDefault(config, "SseType", defaultType);
+ String key = ctx.resolveOptional(config, "KmsKeyArn");
+ if ((type != null && !"AES256".equals(type) && !"aws:kms".equals(type))
+ || (key != null && !"aws:kms".equals(type))) {
+ throw validation("EncryptionConfiguration requires AES256 or aws:kms; KmsKeyArn requires aws:kms.");
+ }
+ if (type == null) {
+ return null;
+ }
+ Map<String, String> result = new LinkedHashMap<>();
+ result.put("sseType", type);
+ if (key != null) {
+ if (key.length() > 2048 || !KMS_KEY_ARN.matcher(key).matches()) {
+ throw validation("KmsKeyArn must be a KMS key ARN of at most 2048 characters.");
+ }
+ result.put("kmsKeyArn", key);
+ }
+ return result;
+ }
+
+ private static String required(JsonNode props, String name, ProvisionContext ctx) {
+ String value = ctx.resolveOrDefault(props, name, null);
+ if (value == null) {
+ throw validation(name + " is required for AWS::S3Vectors::Index.");
+ }
+ return value;
+ }
+
+ private static JsonNode readProperties(StackResource resource) {
+ return readJson(resource.getAttributes().getOrDefault(PROPERTIES, "{}"));
+ }
+
+ private static JsonNode readJson(String json) {
+ try {
+ return MAPPER.readTree(json);
+ } catch (JsonProcessingException e) {
+ throw new IllegalStateException("Cannot read S3 Vectors CloudFormation update state", e);
+ }
+ }
+
+ private static void snapshotTags(StackResource resource, Map<String, String> tags) {
+ resource.getAttributes().put(TAG_SNAPSHOT, MAPPER.valueToTree(tags).toString());
+ }
+
+ private static AwsException validation(String message) {
+ return new AwsException("ValidationError", message, 400);
+ }
+
+ @Override
+ public void delete(StackResource resource, String region) {
+ if (!CfnResourceDispatcher.isStub(resource.getPhysicalId(), resource.getAttributes())) {
+ delete(resource.getResourceType(), resource.getPhysicalId(), region);
+ }
+ }
+
+ @Override
+ public void delete(String resourceType, String physicalId, String region) {
+ boolean index = "AWS::S3Vectors::Index".equals(resourceType);
+ String[] parts = arnParts(physicalId, index);
+ CfnDeletes.safeDelete("S3 Vectors resource", physicalId, () -> {
+ if (index) {
+ service.deleteIndex(parts[1], parts[3], region);
+ } else {
+ service.deleteVectorBucket(parts[1], region);
+ }
+ }, "NotFoundException");
+ }
+
+ @Override
+ public boolean rollbackUpdate(StackResource resource) {
+ boolean replaced = ReplacementCleanup.rollback(resource, this::delete);
+ String prior = resource.getAttributes().remove(PROPERTIES_PRIOR);
+ if (prior != null) {
+ if (prior.isEmpty()) {
+ resource.getAttributes().remove(PROPERTIES);
+ } else {
+ resource.getAttributes().put(PROPERTIES, prior);
+ }
+ }
+ if (replaced) {
+ return true;
+ }
+ String snapshot = resource.getAttributes().get(TAG_SNAPSHOT);
+ if (snapshot == null) {
+ return false;
+ }
+ Map<String, String> tags = new LinkedHashMap<>();
+ readJson(snapshot).fields().forEachRemaining(entry -> tags.put(entry.getKey(), entry.getValue().asText()));
+ String region = AwsArnUtils.parse(resource.getPhysicalId()).region();
+ boolean index = "AWS::S3Vectors::Index".equals(resource.getResourceType());
+ String[] parts = arnParts(resource.getPhysicalId(), index);
+ if (index) {
+ service.replaceIndexTags(parts[1], parts[3], tags, region);
+ } else {
+ service.replaceBucketTags(parts[1], tags, region);
+ }
+ resource.getAttributes().remove(TAG_SNAPSHOT);
+ return true;
+ }
+
+ @Override
+ public boolean hasReplacementUpdate(StackResource resource) {
+ return ReplacementCleanup.hasReplacement(resource);
+ }
+
+ @Override
+ public String updateCleanupPhysicalId(StackResource resource) {
+ return ReplacementCleanup.cleanupPhysicalId(resource);
+ }
+
+ @Override
+ public UpdateCleanupResult completeUpdate(StackResource resource) {
+ resource.getAttributes().remove(PROPERTIES_PRIOR);
+ return ReplacementCleanup.complete(resource, this::delete);
+ }
+
+ @Override
+ public void clearUpdate(StackResource resource) {
+ resource.getAttributes().remove(PROPERTIES_PRIOR);
+ resource.getAttributes().remove(TAG_SNAPSHOT);
+ ReplacementCleanup.clear(resource);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java b/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java
index e73a4462c0..82a8d5bec8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsService.java
@@ -230,6 +230,23 @@ public class S3VectorsService {
}
}
+ public void replaceBucketTags(String bucketName, Map<String, String> tags, String region) {
+ synchronized (lockFor(bucketName, region)) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ bucket.setTags(new ConcurrentHashMap<>(tags));
+ store.put(buildStorageKey(region, bucketName), bucket);
+ }
+ }
+
+ public void replaceIndexTags(String bucketName, String indexName, Map<String, String> tags, String region) {
+ synchronized (lockFor(bucketName, region)) {
+ VectorBucket bucket = getVectorBucket(bucketName, region);
+ VectorIndex index = getIndex(bucket, indexName);
+ index.setTags(new ConcurrentHashMap<>(tags));
+ store.put(buildStorageKey(region, bucketName), bucket);
+ }
+ }
+
public void putVectors(String bucketName, String indexName, List<VectorData> vectors, String region) {
synchronized (lockFor(bucketName, region)) {
VectorBucket bucket = getVectorBucket(bucketName, region);
diff --git a/src/main/resources/cloudformation/create-only-properties.json b/src/main/resources/cloudformation/create-only-properties.json
index ef6bad78f5..9f43ad2c07 100644
--- a/src/main/resources/cloudformation/create-only-properties.json
+++ b/src/main/resources/cloudformation/create-only-properties.json
@@ -718,6 +718,20 @@
"AWS::S3::BucketPolicy": [
"Bucket"
],
+ "AWS::S3Vectors::Index": [
+ "DataType",
+ "Dimension",
+ "DistanceMetric",
+ "EncryptionConfiguration",
+ "IndexName",
+ "MetadataConfiguration",
+ "VectorBucketArn",
+ "VectorBucketName"
+ ],
+ "AWS::S3Vectors::VectorBucket": [
+ "VectorBucketName",
+ "EncryptionConfiguration"
+ ],
"AWS::Scheduler::ScheduleGroup": [
"Name"
],
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnCreateOnlyPropertiesTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnCreateOnlyPropertiesTest.java
index 9cfd78d5ec..097702f249 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnCreateOnlyPropertiesTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnCreateOnlyPropertiesTest.java
@@ -4,11 +4,25 @@ import org.junit.jupiter.api.Test;
import java.util.Set;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CfnCreateOnlyPropertiesTest {
+ @Test
+ void s3VectorsCreateOnlyPropertiesMatchTheRegistrySchemas() {
+ assertEquals(Set.of("DataType", "Dimension", "DistanceMetric", "EncryptionConfiguration", "IndexName",
+ "MetadataConfiguration", "VectorBucketArn", "VectorBucketName"),
+ CfnCreateOnlyProperties.getCreateOnlyProperties("AWS::S3Vectors::Index"));
+ assertEquals(Set.of("VectorBucketName", "EncryptionConfiguration"),
+ CfnCreateOnlyProperties.getCreateOnlyProperties("AWS::S3Vectors::VectorBucket"));
+ assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::S3Vectors::Index", "Dimension"));
+ assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::S3Vectors::VectorBucket", "EncryptionConfiguration"));
+ assertFalse(CfnCreateOnlyProperties.isCreateOnly("AWS::S3Vectors::Index", "Tags"));
+ assertFalse(CfnCreateOnlyProperties.isCreateOnly("AWS::S3Vectors::VectorBucket", "Tags"));
+ }
+
@Test
void isCreateOnly_matchesSchemaDefinedProperties() {
assertTrue(CfnCreateOnlyProperties.isCreateOnly("AWS::Redshift::Cluster", "DBName"));
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java
index ac05b7333b..342970e2f5 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java
@@ -98,6 +98,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.RedshiftC
import io.github.hectorvent.floci.services.cloudformation.provisioners.RedshiftServerlessCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.Route53CfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.S3CfnProvisioner;
+import io.github.hectorvent.floci.services.cloudformation.provisioners.S3VectorsCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SchedulerScheduleCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SchedulerScheduleGroupCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SecretTargetAttachmentCfnProvisioner;
@@ -151,6 +152,7 @@ import io.github.hectorvent.floci.services.redshift.RedshiftService;
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessService;
import io.github.hectorvent.floci.services.route53.Route53Service;
import io.github.hectorvent.floci.services.s3.S3Service;
+import io.github.hectorvent.floci.services.s3vectors.S3VectorsService;
import io.github.hectorvent.floci.services.scheduler.SchedulerService;
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
import io.github.hectorvent.floci.services.ses.SesIdentityService;
@@ -192,6 +194,7 @@ final class CfnProvisionerFixture {
static final class Builder {
private S3Service s3Service;
+ private S3VectorsService s3VectorsService;
private SnsService snsService;
private SesService sesService;
private SesIdentityService sesIdentityService;
@@ -306,6 +309,9 @@ final class CfnProvisionerFixture {
discovered.add(new CustomResourceCfnProvisioner(lambdaService, objectMapper,
customResourceResponseStore, reachableEndpoint));
}
+ if (s3VectorsService != null) {
+ discovered.add(new S3VectorsCfnProvisioner(s3VectorsService));
+ }
if (s3Service != null) {
discovered.add(new S3CfnProvisioner(s3Service));
}
@@ -508,6 +514,11 @@ final class CfnProvisionerFixture {
return discovered;
}
+ public Builder s3Vectors(S3VectorsService v) {
+ this.s3VectorsService = v;
+ return this;
+ }
+
public Builder s3(S3Service v) {
this.s3Service = v;
return this;
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3VectorsCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3VectorsCfnProvisionerTest.java
new file mode 100644
index 0000000000..80f7e810d2
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3VectorsCfnProvisionerTest.java
@@ -0,0 +1,451 @@
+package io.github.hectorvent.floci.services.cloudformation.provisioners;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
+import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
+import io.github.hectorvent.floci.services.s3vectors.S3VectorsService;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorBucket;
+import io.github.hectorvent.floci.services.s3vectors.model.VectorIndex;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+class S3VectorsCfnProvisionerTest {
+
+ private static final String REGION = "us-east-1";
+ private static final String BUCKET_ARN = "arn:aws:s3vectors:us-east-1:000000000000:bucket/my-bucket";
+ private static final String INDEX_ARN = BUCKET_ARN + "/index/my-index";
+ private static final String KMS_KEY_ARN = "arn:aws:kms:us-east-1:000000000000:key/1234abcd-12ab-34cd-56ef-1234567890ab";
+ private static final Instant CREATION_TIME = Instant.parse("2026-01-01T00:00:00Z");
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+ private final S3VectorsService service = mock(S3VectorsService.class);
+ private final S3VectorsCfnProvisioner provisioner = new S3VectorsCfnProvisioner(service);
+
+ private ProvisionContext context(String prior) {
+ CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
+ when(engine.resolve(any())).thenAnswer(invocation -> {
+ JsonNode node = invocation.getArgument(0);
+ return node == null || node.isNull() || node.isMissingNode() ? null : node.asText();
+ });
+ when(engine.resolveNode(any())).thenAnswer(invocation -> invocation.getArgument(0));
+ when(engine.resolveStringList(any())).thenAnswer(invocation -> {
+ JsonNode node = invocation.getArgument(0);
+ return MAPPER.convertValue(node, MAPPER.getTypeFactory().constructCollectionType(List.class, String.class));
+ });
+ return new ProvisionContext(engine, REGION, "000000000000", "MyStack", prior);
+ }
+
+ private static StackResource resource(String type) {
+ StackResource resource = new StackResource();
+ resource.setLogicalId("Vectors");
+ resource.setResourceType("AWS::S3Vectors::" + type);
+ return resource;
+ }
+
+ private static ObjectNode props(String json) throws Exception {
+ return (ObjectNode) MAPPER.readTree(json);
+ }
+
+ private static ObjectNode indexProps() throws Exception {
+ return props("""
+ {"VectorBucketArn":"%s","IndexName":"my-index","Dimension":3,
+ "DataType":"float32","DistanceMetric":"cosine"}
+ """.formatted(BUCKET_ARN));
+ }
+
+ private void stubCreates() {
+ when(service.createVectorBucket(anyString(), any(), anyMap(), eq(REGION)))
+ .thenAnswer(invocation -> {
+ VectorBucket bucket = new VectorBucket(invocation.getArgument(0),
+ BUCKET_ARN.replace("my-bucket", invocation.getArgument(0)), invocation.getArgument(1));
+ bucket.setCreationTime(CREATION_TIME);
+ return bucket;
+ });
+ when(service.createIndex(anyString(), anyString(), anyInt(), anyString(), anyString(),
+ anyList(), any(), anyMap(), eq(REGION))).thenAnswer(invocation -> {
+ VectorIndex index = new VectorIndex(invocation.getArgument(1),
+ BUCKET_ARN + "/index/" + invocation.getArgument(1), invocation.getArgument(0),
+ invocation.getArgument(2), invocation.getArgument(3), invocation.getArgument(4));
+ index.setCreationTime(CREATION_TIME);
+ return index;
+ });
+ }
+
+ @Test
+ void bucketMapsEncryptionAndTagsAndExposesArnAndCreationTime() throws Exception {
+ stubCreates();
+ StackResource resource = resource("VectorBucket");
+ provisioner.provision(resource, props("""
+ {"VectorBucketName":"my-bucket","EncryptionConfiguration":{"SseType":"aws:kms","KmsKeyArn":"%s"},
+ "Tags":[{"Key":"team","Value":"search"}]}
+ """.formatted(KMS_KEY_ARN)), context(null));
+
+ verify(service).createVectorBucket("my-bucket", Map.of("sseType", "aws:kms", "kmsKeyArn", KMS_KEY_ARN),
+ Map.of("team", "search"), REGION);
+ assertEquals(BUCKET_ARN, resource.getPhysicalId());
+ assertEquals(BUCKET_ARN, resource.getAttributes().get("VectorBucketArn"));
+ assertEquals(CREATION_TIME.toString(), resource.getAttributes().get("CreationTime"));
+ assertEquals(Set.of("VectorBucketArn", "CreationTime", "__FlociS3VectorsProperties"),
+ resource.getAttributes().keySet());
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"\"AES256\"", "[]", "42", "true"})
+ void malformedEncryptionConfigurationsFailBeforeCreatingAnything(String configuration) throws Exception {
+ for (String type : List.of("VectorBucket", "Index")) {
+ ObjectNode props = encryptionProps(type, MAPPER.readTree(configuration));
+ AwsException error = assertThrows(AwsException.class,
+ () -> provisioner.provision(resource(type), props, context(null)));
+ assertEquals("ValidationError", error.getErrorCode());
+ assertTrue(error.getMessage().contains("EncryptionConfiguration must be an object"));
+ }
+ verifyNoInteractions(service);
+ }
+
+ static Stream<String> invalidKmsKeyArns() {
+ return Stream.of("key", "1234abcd-12ab-34cd-56ef-1234567890ab", "alias/my-key", "", " ",
+ KMS_KEY_ARN.replace(":kms:", ":s3:"), KMS_KEY_ARN.replace(":key/", ":alias/"),
+ KMS_KEY_ARN.replace("000000000000", "123"), KMS_KEY_ARN.replace("000000000000", "abcdefghijkl"),
+ KMS_KEY_ARN.replace("us-east-1", "US-EAST-1"), KMS_KEY_ARN.replace("arn:aws:", "arn:invalid:"),
+ "arn:aws:kms:us-east-1:000000000000:key/", KMS_KEY_ARN + "a".repeat(2049 - KMS_KEY_ARN.length()));
+ }
+
+ @ParameterizedTest
+ @MethodSource("invalidKmsKeyArns")
+ void invalidKmsKeyArnsFailBeforeCreatingAnything(String key) throws Exception {
+ ObjectNode configuration = MAPPER.createObjectNode().put("SseType", "aws:kms").put("KmsKeyArn", key);
+ for (String type : List.of("VectorBucket", "Index")) {
+ ObjectNode props = encryptionProps(type, configuration);
+ AwsException error = assertThrows(AwsException.class,
+ () -> provisioner.provision(resource(type), props, context(null)));
+ assertEquals("ValidationError", error.getErrorCode());
+ assertTrue(error.getMessage().contains("KmsKeyArn"));
+ }
+ verifyNoInteractions(service);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"us-east-1", "us-gov-west-1", "cn-north-1", "us-iso-east-1", "us-isob-east-1",
+ "eu-isoe-west-1", "us-isof-south-1", "eusc-de-east-1"})
+ void kmsKeyArnsArePreservedAcrossPartitions(String region) throws Exception {
+ stubCreates();
+ String key = AwsArnUtils.Arn.of("kms", region, "000000000000",
+ "key/1234abcd-12ab-34cd-56ef-1234567890ab").toString();
+ ObjectNode configuration = MAPPER.createObjectNode().put("SseType", "aws:kms").put("KmsKeyArn", key);
+ for (String type : List.of("VectorBucket", "Index")) {
+ provisioner.provision(resource(type), encryptionProps(type, configuration), context(null));
+ }
+ Map<String, String> expected = Map.of("sseType", "aws:kms", "kmsKeyArn", key);
+ verify(service).createVectorBucket("my-bucket", expected, Map.of(), REGION);
+ verify(service).createIndex("my-bucket", "my-index", 3, "float32", "cosine",
+ List.of(), expected, Map.of(), REGION);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"null", "{}", "{\"SseType\":null}"})
+ void optionalEncryptionConfigurationPreservesDefaults(String configuration) throws Exception {
+ stubCreates();
+ JsonNode config = MAPPER.readTree(configuration);
+ for (String type : List.of("VectorBucket", "Index")) {
+ provisioner.provision(resource(type), encryptionProps(type, config), context(null));
+ }
+ Map<String, String> expected = config.isNull() ? null : Map.of("sseType", "AES256");
+ verify(service).createVectorBucket("my-bucket", expected, Map.of(), REGION);
+ verify(service).createIndex("my-bucket", "my-index", 3, "float32", "cosine",
+ List.of(), null, Map.of(), REGION);
+ }
+
+ private static ObjectNode encryptionProps(String type, JsonNode configuration) throws Exception {
+ ObjectNode props = "Index".equals(type) ? indexProps()
+ : MAPPER.createObjectNode().put("VectorBucketName", "my-bucket");
+ props.set("EncryptionConfiguration", configuration);
+ return props;
+ }
+
+ @Test
+ void indexMapsBucketArnAndMetadataConfiguration() throws Exception {
+ stubCreates();
+ StackResource resource = resource("Index");
+ ObjectNode props = indexProps();
+ props.set("MetadataConfiguration", MAPPER.readTree("{\"NonFilterableMetadataKeys\":[\"text\"]}"));
+ provisioner.provision(resource, props, context(null));
+
+ verify(service).createIndex("my-bucket", "my-index", 3, "float32", "cosine",
+ List.of("text"), null, Map.of(), REGION);
+ assertEquals(INDEX_ARN, resource.getPhysicalId());
+ assertEquals(INDEX_ARN, resource.getAttributes().get("IndexArn"));
+ assertEquals(CREATION_TIME.toString(), resource.getAttributes().get("CreationTime"));
+ }
+
+ @Test
+ void missingRequiredIndexPropertiesFailBeforeCreatingAnything() throws Exception {
+ for (String required : List.of("DataType", "Dimension", "DistanceMetric")) {
+ ObjectNode props = indexProps();
+ props.remove(required);
+ AwsException error = assertThrows(AwsException.class,
+ () -> provisioner.provision(resource("Index"), props, context(null)));
+ assertTrue(error.getMessage().contains(required));
+ }
+ verifyNoInteractions(service);
+ }
+
+ @Test
+ void invalidBucketSelectorsFailBeforeCreatingAnything() throws Exception {
+ for (String arn : List.of("not-an-arn", BUCKET_ARN + "/index/x",
+ BUCKET_ARN.replace("us-east-1", "us-west-2"), BUCKET_ARN.replace("000000000000", "111111111111"))) {
+ ObjectNode props = indexProps().put("VectorBucketArn", arn);
+ assertThrows(AwsException.class, () -> provisioner.provision(resource("Index"), props, context(null)));
+ }
+ ObjectNode missing = indexProps();
+ missing.remove("VectorBucketArn");
+ assertThrows(AwsException.class, () -> provisioner.provision(resource("Index"), missing, context(null)));
+ ObjectNode both = indexProps().put("VectorBucketName", "my-bucket");
+ assertThrows(AwsException.class, () -> provisioner.provision(resource("Index"), both, context(null)));
+ verifyNoInteractions(service);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"", " ", "\t", "Uppercase", "under_score", "dot.name", "ab", "-bucket", "bucket-",
+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"})
+ void invalidBucketNamesAreRejectedForBothSelectors(String name) throws Exception {
+ for (String selector : List.of("VectorBucketName", "VectorBucketArn")) {
+ ObjectNode props = indexProps();
+ props.remove("VectorBucketArn");
+ props.put(selector, "VectorBucketName".equals(selector) ? name : BUCKET_ARN.replace("my-bucket", name));
+ AwsException error = assertThrows(AwsException.class,
+ () -> provisioner.provision(resource("Index"), props, context(null)));
+ assertEquals("ValidationError", error.getErrorCode());
+ }
+ verifyNoInteractions(service);
+ }
+
+ @Test
+ void blankExplicitResourceNamesAreRejected() throws Exception {
+ for (String name : List.of("", " ")) {
+ assertThrows(AwsException.class, () -> provisioner.provision(resource("VectorBucket"),
+ MAPPER.createObjectNode().put("VectorBucketName", name), context(null)));
+ assertThrows(AwsException.class, () -> provisioner.provision(resource("Index"),
+ indexProps().put("IndexName", name), context(null)));
+ }
+ assertThrows(AwsException.class, () -> provisioner.provision(resource("Index"),
+ indexProps().put("VectorBucketName", ""), context(null)));
+ verifyNoInteractions(service);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"VectorBucket", "Index"})
+ void deletionSkipsOnlyConfirmedLegacyStubs(String type) {
+ StackResource resource = legacyStub(type);
+ assertDoesNotThrow(() -> provisioner.delete(resource, REGION));
+ resource.getAttributes().clear();
+ assertThrows(AwsException.class, () -> provisioner.delete(resource, REGION));
+ verifyNoInteractions(service);
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void legacyBucketsBecomeRealResourcesAndCanRollBack(boolean named) throws Exception {
+ stubCreates();
+ StackResource resource = legacyStub("VectorBucket");
+ ObjectNode props = named ? props("{\"VectorBucketName\":\"my-bucket\"}") : props("{}");
+ provisioner.provision(resource, props, context(resource.getPhysicalId()));
+ String name = resource.getPhysicalId().substring(resource.getPhysicalId().lastIndexOf('/') + 1);
+ assertEquals(BUCKET_ARN.replace("my-bucket", name), resource.getPhysicalId());
+ assertEquals(resource.getPhysicalId(), resource.getAttributes().get("VectorBucketArn"));
+ assertNotNull(resource.getAttributes().get("CreationTime"));
+ verify(service).createVectorBucket(name, null, Map.of(), REGION);
+ verify(service, never()).getVectorBucket(anyString(), anyString());
+ assertTrue(provisioner.rollbackUpdate(resource));
+ assertTrue(CfnResourceDispatcher.isStub(resource.getPhysicalId(), resource.getAttributes()));
+ assertFalse(resource.getAttributes().containsKey("__FlociS3VectorsProperties"));
+ verify(service).deleteVectorBucket(name, REGION);
+ provisioner.delete(resource, REGION);
+ verifyNoMoreInteractions(service);
+ }
+
+ @Test
+ void legacyIndexMigrationDoesNotTryToDeleteThePlaceholder() throws Exception {
+ stubCreates();
+ StackResource resource = legacyStub("Index");
+ provisioner.provision(resource, indexProps(), context(resource.getPhysicalId()));
+ assertEquals(INDEX_ARN, resource.getPhysicalId());
+ assertEquals(INDEX_ARN, resource.getAttributes().get("IndexArn"));
+ assertNotNull(resource.getAttributes().get("CreationTime"));
+ assertTrue(provisioner.completeUpdate(resource).complete());
+ provisioner.clearUpdate(resource);
+ verify(service).createIndex("my-bucket", "my-index", 3, "float32", "cosine",
+ List.of(), null, Map.of(), REGION);
+ verifyNoMoreInteractions(service);
+ }
+
+ private static StackResource legacyStub(String type) {
+ StackResource resource = resource(type);
+ resource.setPhysicalId("Vectors-1a2b3c4d");
+ resource.getAttributes().put("Arn", "arn:aws:stub:::Vectors");
+ return resource;
+ }
+
+ @Test
+ void unnamedBucketKeepsItsIdentityAndCreationTimeDuringTagUpdateAndRollback() throws Exception {
+ stubCreates();
+ StackResource resource = resource("VectorBucket");
+ provisioner.provision(resource, props("{}"), context(null));
+ String arn = resource.getPhysicalId();
+ String name = arn.substring(arn.lastIndexOf('/') + 1);
+ assertTrue(name.matches("mystack-vectors-[0-9a-f]{12}"));
+ String created = resource.getAttributes().get("CreationTime");
+ VectorBucket bucket = new VectorBucket(name, arn, null);
+ bucket.setCreationTime(Instant.parse(created));
+ bucket.setTags(Map.of("old", "value"));
+ when(service.getVectorBucket(name, REGION)).thenReturn(bucket);
+
+ provisioner.provision(resource, props("{\"Tags\":[{\"Key\":\"new\",\"Value\":\"value\"}]}"), context(arn));
+ assertEquals(arn, resource.getPhysicalId());
+ assertEquals(created, resource.getAttributes().get("CreationTime"));
+ verify(service).replaceBucketTags(name, Map.of("new", "value"), REGION);
+ assertTrue(provisioner.rollbackUpdate(resource));
+ verify(service).replaceBucketTags(name, Map.of("old", "value"), REGION);
+ verify(service, times(1)).createVectorBucket(anyString(), any(), anyMap(), eq(REGION));
+ }
+
+ @Test
+ void indexTagUpdatesAndRollbackPreserveIdentity() throws Exception {
+ stubCreates();
+ StackResource resource = resource("Index");
+ provisioner.provision(resource, indexProps(), context(null));
+ VectorIndex index = new VectorIndex("my-index", INDEX_ARN, "my-bucket", 3, "float32", "cosine");
+ index.setCreationTime(CREATION_TIME);
+ index.setTags(Map.of("old", "value"));
+ when(service.getIndex("my-bucket", "my-index", REGION)).thenReturn(index);
+ ObjectNode props = indexProps();
+ props.set("Tags", MAPPER.readTree("[{\"Key\":\"new\",\"Value\":\"value\"}]"));
+
+ provisioner.provision(resource, props, context(INDEX_ARN));
+
+ assertEquals(INDEX_ARN, resource.getPhysicalId());
+ assertEquals(CREATION_TIME.toString(), resource.getAttributes().get("CreationTime"));
+ verify(service).replaceIndexTags("my-bucket", "my-index", Map.of("new", "value"), REGION);
+ assertTrue(provisioner.rollbackUpdate(resource));
+ verify(service).replaceIndexTags("my-bucket", "my-index", Map.of("old", "value"), REGION);
+ verify(service, times(1)).createIndex(anyString(), anyString(), anyInt(), anyString(), anyString(),
+ anyList(), any(), anyMap(), eq(REGION));
+ }
+
+ @Test
+ void immutableUpdateReplacesGeneratedIndexAndCleansUpPriorIndex() throws Exception {
+ stubCreates();
+ StackResource resource = resource("Index");
+ ObjectNode props = indexProps();
+ props.remove("IndexName");
+ provisioner.provision(resource, props, context(null));
+ String oldArn = resource.getPhysicalId();
+ provisioner.provision(resource, props.deepCopy().put("Dimension", 4), context(oldArn));
+
+ assertNotEquals(oldArn, resource.getPhysicalId());
+ assertTrue(provisioner.hasReplacementUpdate(resource));
+ assertEquals(oldArn, provisioner.updateCleanupPhysicalId(resource));
+ assertTrue(provisioner.completeUpdate(resource).complete());
+ assertFalse(resource.getAttributes().containsKey("__FlociS3VectorsPropertiesBeforeUpdate"));
+ assertEquals(props.deepCopy().put("Dimension", 4).toString(),
+ resource.getAttributes().get("__FlociS3VectorsProperties"));
+ verify(service).deleteIndex("my-bucket", oldArn.substring(oldArn.lastIndexOf('/') + 1), REGION);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"VectorBucket", "Index"})
+ void tagUpdateAfterReplacementRollbackReusesOriginalResource(String type) throws Exception {
+ stubCreates();
+ boolean index = "Index".equals(type);
+ StackResource resource = resource(type);
+ ObjectNode original = index ? indexProps() : props("{\"VectorBucketName\":\"my-bucket\"}");
+ provisioner.provision(resource, original, context(null));
+ String originalArn = resource.getPhysicalId();
+ ObjectNode replacement = original.deepCopy().put(index ? "IndexName" : "VectorBucketName", "replacement");
+ provisioner.provision(resource, replacement, context(originalArn));
+
+ assertTrue(provisioner.rollbackUpdate(resource));
+ assertEquals(originalArn, resource.getPhysicalId());
+ assertEquals(original.toString(), resource.getAttributes().get("__FlociS3VectorsProperties"));
+ assertFalse(resource.getAttributes().containsKey("__FlociS3VectorsPropertiesBeforeUpdate"));
+
+ VectorBucket bucket = new VectorBucket("my-bucket", BUCKET_ARN, null);
+ bucket.setCreationTime(CREATION_TIME);
+ when(service.getVectorBucket("my-bucket", REGION)).thenReturn(bucket);
+ VectorIndex vectorIndex = new VectorIndex("my-index", INDEX_ARN, "my-bucket", 3, "float32", "cosine");
+ vectorIndex.setCreationTime(CREATION_TIME);
+ when(service.getIndex("my-bucket", "my-index", REGION)).thenReturn(vectorIndex);
+ ObjectNode tagged = original.deepCopy();
+ tagged.set("Tags", MAPPER.readTree("[{\"Key\":\"version\",\"Value\":\"second\"}]"));
+
+ provisioner.provision(resource, tagged, context(originalArn));
+
+ assertEquals(originalArn, resource.getPhysicalId());
+ assertEquals(CREATION_TIME.toString(), resource.getAttributes().get("CreationTime"));
+ assertFalse(provisioner.hasReplacementUpdate(resource));
+ if (index) {
+ verify(service).replaceIndexTags("my-bucket", "my-index", Map.of("version", "second"), REGION);
+ verify(service, times(2)).createIndex(anyString(), anyString(), anyInt(), anyString(), anyString(),
+ anyList(), any(), anyMap(), eq(REGION));
+ } else {
+ verify(service).replaceBucketTags("my-bucket", Map.of("version", "second"), REGION);
+ verify(service, times(2)).createVectorBucket(anyString(), any(), anyMap(), eq(REGION));
+ }
+ }
+
+ @Test
+ void replacementRollbackRetainsPropertySnapshotUntilDeletionSucceeds() throws Exception {
+ stubCreates();
+ StackResource resource = resource("Index");
+ provisioner.provision(resource, indexProps(), context(null));
+ provisioner.provision(resource, indexProps().put("IndexName", "replacement"), context(INDEX_ARN));
+ doThrow(new AwsException("ConflictException", "retry deletion", 409)).doNothing()
+ .when(service).deleteIndex("my-bucket", "replacement", REGION);
+
+ assertThrows(AwsException.class, () -> provisioner.rollbackUpdate(resource));
+ assertEquals(indexProps().toString(),
+ resource.getAttributes().get("__FlociS3VectorsPropertiesBeforeUpdate"));
+ assertTrue(provisioner.rollbackUpdate(resource));
+ assertEquals(indexProps().toString(), resource.getAttributes().get("__FlociS3VectorsProperties"));
+ assertFalse(resource.getAttributes().containsKey("__FlociS3VectorsPropertiesBeforeUpdate"));
+ verify(service, times(2)).deleteIndex("my-bucket", "replacement", REGION);
+ }
+
+ @Test
+ void namedReplacementRequiresANewNameAndCanBeRolledBack() throws Exception {
+ stubCreates();
+ StackResource resource = resource("Index");
+ provisioner.provision(resource, indexProps(), context(null));
+ ObjectNode replacement = indexProps().put("Dimension", 4);
+ assertThrows(AwsException.class, () -> provisioner.provision(resource, replacement, context(INDEX_ARN)));
+ provisioner.provision(resource, replacement.put("IndexName", "replacement"), context(INDEX_ARN));
+ assertTrue(provisioner.rollbackUpdate(resource));
+ assertEquals(INDEX_ARN, resource.getPhysicalId());
+ verify(service).deleteIndex("my-bucket", "replacement", REGION);
+ verify(service, never()).deleteIndex("my-bucket", "my-index", REGION);
+ }
+
+ @Test
+ void deletionToleratesOnlyMissingResources() {
+ doThrow(new AwsException("NotFoundException", "gone", 404))
+ .when(service).deleteIndex("my-bucket", "my-index", REGION);
+ assertDoesNotThrow(() -> provisioner.delete("AWS::S3Vectors::Index", INDEX_ARN, REGION));
+ doThrow(new AwsException("ConflictException", "not empty", 409))
+ .when(service).deleteVectorBucket("my-bucket", REGION);
+ assertThrows(AwsException.class, () -> provisioner.delete("AWS::S3Vectors::VectorBucket", BUCKET_ARN, REGION));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsServiceTest.java
index 660af4a2ea..eceb25534c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsServiceTest.java
@@ -59,6 +59,26 @@ class S3VectorsServiceTest {
assertEquals(Map.of("old", "value"), restoredIndex.getTags());
}
+ @Test
+ void persistsCreationTimesConfigurationAndReconciledTags() throws Exception {
+ Map<String, String> encryption = Map.of("sseType", "aws:kms", "kmsKeyArn", "key");
+ VectorBucket bucket = service.createVectorBucket("bucket", encryption, Map.of("old", "value"), REGION);
+ VectorIndex index = service.createIndex("bucket", "index", 3, "float32", "cosine", List.of("text"),
+ null, Map.of("old", "value"), REGION);
+ service.replaceBucketTags("bucket", Map.of("new", "value"), REGION);
+ service.replaceIndexTags("bucket", "index", Map.of(), REGION);
+
+ ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
+ VectorBucket restored = mapper.readValue(mapper.writeValueAsString(bucket), VectorBucket.class);
+ VectorIndex restoredIndex = restored.getIndexes().get("index");
+ assertEquals(bucket.getCreationTime(), restored.getCreationTime());
+ assertEquals(index.getCreationTime(), restoredIndex.getCreationTime());
+ assertEquals(encryption, restoredIndex.getEncryptionConfiguration());
+ assertEquals(List.of("text"), restoredIndex.getNonFilterableMetadataKeys());
+ assertEquals(Map.of("new", "value"), restored.getTags());
+ assertEquals(Map.of(), restoredIndex.getTags());
+ }
+
@Test
void indexEncryptionCanOverrideTheBucketDefault() {
VectorBucket bucket = service.createVectorBucket("bucket", null, REGION);
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsWriteLockTest.java b/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsWriteLockTest.java
index e9f9bb7e90..a477cdd5d1 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsWriteLockTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3vectors/S3VectorsWriteLockTest.java
@@ -95,6 +95,61 @@ class S3VectorsWriteLockTest {
assertEquals(Map.of("new", "tag"), service.getVectorBucket("bucket", REGION).getTags());
}
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void bucketAndIndexTagUpdatesPreserveEachOther(boolean copyOnAccess) throws Exception {
+ setUp(copyOnAccess);
+ createIndex();
+ overlap(() -> service.replaceBucketTags("bucket", Map.of("bucket", "tag"), REGION),
+ () -> service.replaceIndexTags("bucket", "index", Map.of("index", "tag"), REGION));
+ assertEquals(Map.of("bucket", "tag"), service.getVectorBucket("bucket", REGION).getTags());
+ assertEquals(Map.of("index", "tag"), service.getIndex("bucket", "index", REGION).getTags());
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void bucketTagsDoNotOverwriteConcurrentIndexCreation(boolean copyOnAccess) throws Exception {
+ setUp(copyOnAccess);
+ overlap(() -> service.replaceBucketTags("bucket", Map.of("bucket", "tag"), REGION), this::createIndex);
+ assertEquals(Map.of("bucket", "tag"), service.getVectorBucket("bucket", REGION).getTags());
+ assertEquals("index", service.getIndex("bucket", "index", REGION).getIndexName());
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void indexTagsPreserveVectorWritesAndDoNotReviveDeletedData(boolean copyOnAccess) throws Exception {
+ setUp(copyOnAccess);
+ createIndex();
+ Runnable tagUpdate = () -> service.replaceIndexTags("bucket", "index", Map.of("index", "tag"), REGION);
+ overlap(tagUpdate, () -> service.putVectors("bucket", "index",
+ List.of(new VectorData("key", List.of(1.0f), Map.of())), REGION));
+ assertEquals(Map.of("index", "tag"), service.getIndex("bucket", "index", REGION).getTags());
+ assertEquals(1, service.getVectors("bucket", "index", List.of("key"), REGION).size());
+
+ overlap(tagUpdate, () -> service.deleteVectors("bucket", "index", List.of("key"), REGION));
+ assertTrue(service.getVectors("bucket", "index", List.of("key"), REGION).isEmpty());
+
+ overlap(tagUpdate, () -> service.deleteIndex("bucket", "index", REGION));
+ AwsException error = assertThrows(AwsException.class, () -> service.getIndex("bucket", "index", REGION));
+ assertEquals("NotFoundException", error.getErrorCode());
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void tagUpdateCannotResurrectADeletedOrRecreatedBucket(boolean copyOnAccess) throws Exception {
+ setUp(copyOnAccess);
+ overlap(() -> service.replaceBucketTags("bucket", Map.of("old", "tag"), REGION),
+ () -> service.deleteVectorBucket("bucket", REGION));
+ assertThrows(AwsException.class, () -> service.getVectorBucket("bucket", REGION));
+
+ service.createVectorBucket("bucket", null, REGION);
+ overlap(() -> service.replaceBucketTags("bucket", Map.of("old", "tag"), REGION), () -> {
+ service.deleteVectorBucket("bucket", REGION);
+ service.createVectorBucket("bucket", null, Map.of("new", "tag"), REGION);
+ });
+ assertEquals(Map.of("new", "tag"), service.getVectorBucket("bucket", REGION).getTags());
+ }
+
private void putVector(String key) {
service.putVectors("bucket", "index", List.of(new VectorData(key, List.of(1.0f), Map.of())), REGION);
}
diff --git a/src/test/resources/cloudformation/supported-resource-types.tsv b/src/test/resources/cloudformation/supported-resource-types.tsv
index 7fbc5be80e..2a771626ad 100644
--- a/src/test/resources/cloudformation/supported-resource-types.tsv
+++ b/src/test/resources/cloudformation/supported-resource-types.tsv
@@ -163,6 +163,8 @@ AWS::Route53::HostedZone Route53CfnProvisioner
AWS::Route53::RecordSet Route53CfnProvisioner
AWS::S3::Bucket S3CfnProvisioner
AWS::S3::BucketPolicy S3CfnProvisioner
+AWS::S3Vectors::Index S3VectorsCfnProvisioner
+AWS::S3Vectors::VectorBucket S3VectorsCfnProvisioner
AWS::SES::EmailIdentity SesCfnProvisioner
AWS::SNS::Subscription SnsCfnProvisioner
AWS::SNS::Topic SnsCfnProvisioner
diff --git a/tools/docs/cfn_resource_types.yaml b/tools/docs/cfn_resource_types.yaml
index 65a3e6c60d..3ca31b6a6b 100644
--- a/tools/docs/cfn_resource_types.yaml
+++ b/tools/docs/cfn_resource_types.yaml
@@ -11,6 +11,7 @@
# entry degrades to a sensible position rather than disappearing.
order:
- AWS::S3
+ - AWS::S3Vectors
- AWS::SQS
- AWS::SNS
- AWS::SES
@@ -77,6 +78,7 @@ display_names:
# Curated where the reading order carries meaning (primary resources before their accessories).
type_order:
AWS::S3: [Bucket, BucketPolicy]
+ AWS::S3Vectors: [VectorBucket, Index]
AWS::SQS: [Queue, QueuePolicy]
AWS::SNS: [Topic, Subscription]
AWS::DynamoDB: [Table, GlobalTable]
@@ -157,6 +159,7 @@ service_labels:
AWS::RedshiftServerless: Redshift Serverless
AWS::Route53: Route 53
AWS::S3: S3
+ AWS::S3Vectors: S3 Vectors
AWS::SNS: SNS
AWS::SES: SES
AWS::SQS: SQS