fix(dynamodb): export the table as of ExportTime (#6132)

* fix(dynamodb): export the table as of ExportTime

* refactor(dynamodb): share the epoch seconds conversions

* fix(dynamodb): treat a table that is still being created as not found on export

* docs(dynamodb): note the writes made before point-in-time recovery is enabled

* fix(dynamodb): round timestamp inputs to milliseconds as AWS does

* fix(dynamodb): check the ListBackups time range limits

* fix(dynamodb): check the ListBackups ExclusiveStartBackupArn length

* refactor(dynamodb): reuse requireBackupSource for the export table lookup
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-22 07:31:07 -04:00
1 parent f7576eda1a
commit da66550c70
12 files changed
+396 -37

No files matched your search

@@ -12,6 +12,8 @@ import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
@@ -53,6 +55,11 @@ class DynamoDbExportTest {
.billingMode(BillingMode.PAY_PER_REQUEST)
.build());
tableArn = tableResp.tableDescription().tableArn();
ddb.updateContinuousBackups(UpdateContinuousBackupsRequest.builder()
.tableName(TABLE_NAME)
.pointInTimeRecoverySpecification(PointInTimeRecoverySpecification.builder()
.pointInTimeRecoveryEnabled(true).build())
.build());
// Insert 3 items
ddb.putItem(PutItemRequest.builder().tableName(TABLE_NAME)
@@ -224,6 +231,46 @@ class DynamoDbExportTest {
.isInstanceOf(software.amazon.awssdk.services.dynamodb.model.DynamoDbException.class);
}
@Test
@Order(8)
void exportTableToPointInTime_exportTime_exportsTheItemsOfThatTime() throws InterruptedException {
Thread.sleep(50);
Instant beforeFourthItem = Instant.now();
Thread.sleep(50);
ddb.putItem(PutItemRequest.builder().tableName(TABLE_NAME)
.item(Map.of(
"pk", AttributeValue.fromS("user-4"),
"sk", AttributeValue.fromS("order-004"),
"total", AttributeValue.fromN("10")))
.build());
ExportDescription desc = ddb.exportTableToPointInTime(ExportTableToPointInTimeRequest.builder()
.tableArn(tableArn)
.s3Bucket(BUCKET_NAME)
.s3Prefix("exports-time")
.exportTime(beforeFourthItem)
.build()).exportDescription();
assertThat(desc.exportTime()).isEqualTo(beforeFourthItem.truncatedTo(ChronoUnit.MILLIS));
try (DynamoDbWaiter waiter = DynamoDbWaiter.builder().client(ddb).build()) {
waiter.waitUntilExportCompleted(r -> r.exportArn(desc.exportArn()));
}
assertThat(ddb.describeExport(DescribeExportRequest.builder().exportArn(desc.exportArn()).build())
.exportDescription().itemCount()).isEqualTo(3L);
}
@Test
@Order(9)
void exportTableToPointInTime_futureExportTime_throwsInvalidExportTimeException() {
assertThatThrownBy(() -> ddb.exportTableToPointInTime(ExportTableToPointInTimeRequest.builder()
.tableArn(tableArn)
.s3Bucket(BUCKET_NAME)
.exportTime(Instant.now().plusSeconds(3600))
.build()))
.isInstanceOf(InvalidExportTimeException.class)
.hasMessageContaining("Export Time is invalid");
}
private String decompressGzip(byte[] data) throws Exception {
try (GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(data));
BufferedReader reader = new BufferedReader(new InputStreamReader(gzip, StandardCharsets.UTF_8))) {