feat(redshift-serverless): add snapshot copy configuration actions (#5798)

* feat(redshift-serverless): add snapshot copy configuration actions

Add CreateSnapshotCopyConfiguration, ListSnapshotCopyConfigurations,
UpdateSnapshotCopyConfiguration and DeleteSnapshotCopyConfiguration. A
configuration is recorded and echoed; Floci copies no snapshot. A namespace has
one configuration at a time and the destination Region must differ from its own.
The configuration is tied to the namespace by the namespace's generated id, so a
namespace recreated under the same name does not inherit it.

Required members come from the AWS model through RedshiftServerlessRequestShapes.
The destination Region name and the retention range are checked by hand because
the model leaves them unconstrained.

* fix(redshift-serverless): validate boundary inputs and scope snapshot copy pagination tokens

* refactor(redshift-serverless): share maxResults range check and invalidPagination helper
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-16 22:42:36 -04:00
1 parent d4158b954b
commit 2a012cf9a4
13 files changed
+476 -18

No files matched your search

@@ -51,7 +51,7 @@ class RedshiftServerlessAdministrationHandlerTest {
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
for (String file : List.of("namespaces", "workgroups", "snapshots", "usagelimits", "resourcepolicies",
"endpointaccess", "customdomains")) {
"endpointaccess", "customdomains", "snapshotcopyconfigurations")) {
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
@@ -91,7 +91,8 @@ class RedshiftServerlessAdministrationHandlerTest {
new RedshiftServerlessAdminJsonHandler(mapper,
new RedshiftServerlessResourcePolicyService(storageFactory, serverlessService, mapper),
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, serverlessService),
customDomains),
customDomains,
new RedshiftServerlessSnapshotCopyService(storageFactory, regionResolver, serverlessService)),
customDomains);
}
@@ -455,6 +456,72 @@ class RedshiftServerlessAdministrationHandlerTest {
}
}
@Test
void snapshotCopyConfigurationHasOneDestinationPerNamespace() {
namespace("copy-ns");
JsonNode created = ok("CreateSnapshotCopyConfiguration", "{\"namespaceName\":\"copy-ns\","
+ "\"destinationRegion\":\"us-west-2\",\"snapshotRetentionPeriod\":14,"
+ "\"destinationKmsKeyId\":\"key-1\"}").get("snapshotCopyConfiguration");
String id = created.get("snapshotCopyConfigurationId").textValue();
assertEquals("copy-ns", created.get("namespaceName").textValue());
assertEquals("us-west-2", created.get("destinationRegion").textValue());
assertEquals("key-1", created.get("destinationKmsKeyId").textValue());
assertEquals(14, created.get("snapshotRetentionPeriod").intValue());
assertTrue(created.get("snapshotCopyConfigurationArn").textValue().contains(":snapshotcopyconfiguration/"));
assertEquals("ConflictException", errorType("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"us-west-2\"}"));
assertEquals("ConflictException", errorType("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"eu-west-1\"}"));
assertEquals("ValidationException", errorType("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"us-east-1\"}"));
assertEquals("ValidationException", errorType("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"US-WEST-2\"}"));
assertEquals("ValidationException", errorType("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"invalid_region!\"}"));
assertEquals("ResourceNotFoundException", errorType("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"nope-ns\",\"destinationRegion\":\"us-west-2\"}"));
assertEquals(30, ok("UpdateSnapshotCopyConfiguration", "{\"snapshotCopyConfigurationId\":\"" + id
+ "\",\"snapshotRetentionPeriod\":30}").get("snapshotCopyConfiguration")
.get("snapshotRetentionPeriod").intValue());
assertEquals("ValidationException", errorType("UpdateSnapshotCopyConfiguration",
"{\"snapshotCopyConfigurationId\":\"" + id + "\",\"snapshotRetentionPeriod\":0}"));
assertEquals(1, ok("ListSnapshotCopyConfigurations", "{\"namespaceName\":\"copy-ns\"}")
.get("snapshotCopyConfigurations").size());
assertEquals(id, ok("DeleteSnapshotCopyConfiguration", "{\"snapshotCopyConfigurationId\":\"" + id + "\"}")
.get("snapshotCopyConfiguration").get("snapshotCopyConfigurationId").textValue());
assertEquals(0, ok("ListSnapshotCopyConfigurations", "{}").get("snapshotCopyConfigurations").size());
assertEquals("eu-west-1", ok("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"eu-west-1\"}")
.get("snapshotCopyConfiguration").get("destinationRegion").textValue());
}
@Test
void snapshotCopyPagingWalksPagesAndValidatesInputs() {
for (String name : List.of("page-copy-a", "page-copy-b", "page-copy-c")) {
namespace(name);
ok("CreateSnapshotCopyConfiguration", "{\"namespaceName\":\"" + name
+ "\",\"destinationRegion\":\"us-west-2\"}");
}
JsonNode firstPage = ok("ListSnapshotCopyConfigurations", "{\"maxResults\":2}");
assertEquals(2, firstPage.get("snapshotCopyConfigurations").size());
assertTrue(firstPage.has("nextToken"));
String token = firstPage.get("nextToken").textValue();
JsonNode secondPage = ok("ListSnapshotCopyConfigurations", "{\"nextToken\":\"" + token + "\"}");
assertEquals(1, secondPage.get("snapshotCopyConfigurations").size());
assertFalse(secondPage.has("nextToken"));
assertEquals("ValidationException", errorType("ListSnapshotCopyConfigurations", "{\"maxResults\":0}"));
assertEquals("ValidationException", errorType("ListSnapshotCopyConfigurations", "{\"maxResults\":101}"));
assertEquals("InvalidPaginationException",
errorType("ListSnapshotCopyConfigurations", "{\"nextToken\":\"bad-token\"}"));
}
@Test
void tracksAreTheTwoAwsReleaseTracks() {
JsonNode track = ok("GetTrack", "{\"trackName\":\"trailing\"}").get("track");
@@ -538,6 +605,19 @@ class RedshiftServerlessAdministrationHandlerTest {
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
}
@Test
void aNamespaceRecreatedUnderTheSameNameDoesNotInheritCopyConfigurations() {
namespace("recreate-ns");
ok("CreateSnapshotCopyConfiguration", "{\"namespaceName\":\"recreate-ns\",\"destinationRegion\":\"us-west-2\"}");
ok("DeleteNamespace", "{\"namespaceName\":\"recreate-ns\"}");
namespace("recreate-ns");
assertEquals(0, ok("ListSnapshotCopyConfigurations", "{\"namespaceName\":\"recreate-ns\"}")
.get("snapshotCopyConfigurations").size());
ok("CreateSnapshotCopyConfiguration", "{\"namespaceName\":\"recreate-ns\",\"destinationRegion\":\"us-west-2\"}");
}
@Test
void aSnapshotRecreatedUnderTheSameNameDoesNotInheritItsPolicy() {
String arn = snapshot("recreate-snap-ns", "recreate-snap");
@@ -707,6 +707,35 @@ class RedshiftServerlessIntegrationTest {
.body("workgroup.customDomainName", nullValue());
}
@Test
void snapshotCopyConfigurationRoundTripsOverTheWire() {
call("CreateNamespace", "{\"namespaceName\":\"copy-ns\",\"adminUsername\":\"admin\"}").statusCode(200);
String copyId = call("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"us-west-2\",\"snapshotRetentionPeriod\":10}")
.statusCode(200)
.body("snapshotCopyConfiguration.destinationRegion", equalTo("us-west-2"))
.extract().path("snapshotCopyConfiguration.snapshotCopyConfigurationId");
call("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"eu-west-1\"}")
.statusCode(400)
.body("__type", equalTo("ConflictException"));
call("DeleteSnapshotCopyConfiguration", "{\"snapshotCopyConfigurationId\":\"" + copyId + "\"}").statusCode(200);
String replacementCopyId = call("CreateSnapshotCopyConfiguration",
"{\"namespaceName\":\"copy-ns\",\"destinationRegion\":\"eu-west-1\"}")
.statusCode(200)
.body("snapshotCopyConfiguration.destinationRegion", equalTo("eu-west-1"))
.extract().path("snapshotCopyConfiguration.snapshotCopyConfigurationId");
call("ListSnapshotCopyConfigurations", "{\"maxResults\":0}")
.statusCode(400)
.body("__type", equalTo("ValidationException"));
call("ListSnapshotCopyConfigurations", "{\"nextToken\":\"bad-token\"}")
.statusCode(400)
.body("__type", equalTo("InvalidPaginationException"));
call("DeleteSnapshotCopyConfiguration", "{\"snapshotCopyConfigurationId\":\"" + replacementCopyId + "\"}")
.statusCode(200);
}
private static io.restassured.response.ValidatableResponse call(String action, String body) {
return given()
.header("X-Amz-Target", TARGET_PREFIX + action)
@@ -95,13 +95,14 @@ class RedshiftServerlessJsonHandlerTest {
new RedshiftServerlessAdminJsonHandler(mapper,
new RedshiftServerlessResourcePolicyService(storageFactory, service, mapper),
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, service),
customDomains),
customDomains,
new RedshiftServerlessSnapshotCopyService(storageFactory, regionResolver, service)),
customDomains);
}
@SuppressWarnings({"unchecked", "rawtypes"})
private static void stubAdministrationStores(StorageFactory storageFactory) {
for (String file : List.of("resourcepolicies", "endpointaccess", "customdomains")) {
for (String file : List.of("resourcepolicies", "endpointaccess", "customdomains", "snapshotcopyconfigurations")) {
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));