fix(dynamodb): support continuous backups PITR actions (#458)

This commit is contained in:
TiM authored and GitHub committed 2026-04-15 01:12:50 -05:00
1 parent ca0395a9e0
commit 3cdb9b0ded
6 files changed
+278

No files matched your search

@@ -53,6 +53,8 @@ public class DynamoDbJsonHandler {
case "UpdateTable" -> handleUpdateTable(request, region);
case "DescribeTimeToLive" -> handleDescribeTimeToLive(request, region);
case "UpdateTimeToLive" -> handleUpdateTimeToLive(request, region);
case "DescribeContinuousBackups" -> handleDescribeContinuousBackups(request, region);
case "UpdateContinuousBackups" -> handleUpdateContinuousBackups(request, region);
case "TransactWriteItems" -> handleTransactWriteItems(request, region);
case "TransactGetItems" -> handleTransactGetItems(request, region);
case "TagResource" -> handleTagResource(request, region);
@@ -528,6 +530,35 @@ public class DynamoDbJsonHandler {
return Response.ok(response).build();
}
private Response handleDescribeContinuousBackups(JsonNode request, String region) {
String tableName = request.path("TableName").asText();
TableDefinition table = dynamoDbService.describeTable(tableName, region);
ObjectNode response = objectMapper.createObjectNode();
response.set("ContinuousBackupsDescription", continuousBackupsDescriptionNode(table));
return Response.ok(response).build();
}
private Response handleUpdateContinuousBackups(JsonNode request, String region) {
String tableName = request.path("TableName").asText();
JsonNode spec = request.path("PointInTimeRecoverySpecification");
boolean enabled = spec.path("PointInTimeRecoveryEnabled").asBoolean(false);
Integer recoveryPeriodInDays = spec.has("RecoveryPeriodInDays")
? spec.path("RecoveryPeriodInDays").asInt()
: null;
if (recoveryPeriodInDays != null && (recoveryPeriodInDays < 1 || recoveryPeriodInDays > 35)) {
throw new AwsException("ValidationException",
"RecoveryPeriodInDays must be between 1 and 35", 400);
}
TableDefinition table = dynamoDbService.updateContinuousBackups(
tableName, enabled, recoveryPeriodInDays, region);
ObjectNode response = objectMapper.createObjectNode();
response.set("ContinuousBackupsDescription", continuousBackupsDescriptionNode(table));
return Response.ok(response).build();
}
private Response handleTransactWriteItems(JsonNode request, String region) {
JsonNode transactItemsNode = request.path("TransactItems");
List<JsonNode> transactItems = new ArrayList<>();
@@ -847,4 +878,18 @@ public class DynamoDbJsonHandler {
return node;
}
private ObjectNode continuousBackupsDescriptionNode(TableDefinition table) {
ObjectNode node = objectMapper.createObjectNode();
node.put("ContinuousBackupsStatus", "ENABLED");
ObjectNode pitrNode = objectMapper.createObjectNode();
pitrNode.put("PointInTimeRecoveryStatus",
table.isPointInTimeRecoveryEnabled() ? "ENABLED" : "DISABLED");
if (table.isPointInTimeRecoveryEnabled()) {
pitrNode.put("RecoveryPeriodInDays", table.getPointInTimeRecoveryRecoveryPeriodInDays());
}
node.set("PointInTimeRecoveryDescription", pitrNode);
return node;
}
}
@@ -799,6 +799,20 @@ public class DynamoDbService {
LOG.infov("Updated TTL for table {0}: enabled={1}, attr={2}", tableName, enabled, ttlAttributeName);
}
public TableDefinition updateContinuousBackups(String tableName, boolean enabled,
Integer recoveryPeriodInDays, String region) {
String storageKey = regionKey(region, tableName);
TableDefinition table = tableStore.get(storageKey)
.orElseThrow(() -> resourceNotFoundException(tableName));
table.setPointInTimeRecoveryEnabled(enabled);
table.setPointInTimeRecoveryRecoveryPeriodInDays(
recoveryPeriodInDays != null ? recoveryPeriodInDays : table.getPointInTimeRecoveryRecoveryPeriodInDays());
tableStore.put(storageKey, table);
LOG.infov("Updated PITR for table {0}: enabled={1}, recoveryPeriodInDays={2}",
tableName, enabled, table.getPointInTimeRecoveryRecoveryPeriodInDays());
return table;
}
static boolean isExpired(JsonNode item, TableDefinition table) {
if (!table.isTtlEnabled() || table.getTtlAttributeName() == null) return false;
JsonNode attr = item.get(table.getTtlAttributeName());
@@ -32,6 +32,8 @@ public class TableDefinition {
private String billingMode; // "PROVISIONED" or "PAY_PER_REQUEST"
private String ttlAttributeName;
private boolean ttlEnabled;
private boolean pointInTimeRecoveryEnabled;
private int pointInTimeRecoveryRecoveryPeriodInDays;
private boolean streamEnabled;
private String streamArn;
private String streamViewType;
@@ -43,6 +45,7 @@ public class TableDefinition {
this.tags = new HashMap<>();
this.globalSecondaryIndexes = new ArrayList<>();
this.localSecondaryIndexes = new ArrayList<>();
this.pointInTimeRecoveryRecoveryPeriodInDays = 35;
this.kinesisStreamingDestinations = new ArrayList<>();
}
@@ -68,6 +71,7 @@ public class TableDefinition {
this.tags = new HashMap<>();
this.globalSecondaryIndexes = new ArrayList<>();
this.localSecondaryIndexes = new ArrayList<>();
this.pointInTimeRecoveryRecoveryPeriodInDays = 35;
this.kinesisStreamingDestinations = new ArrayList<>();
}
@@ -120,6 +124,16 @@ public class TableDefinition {
public boolean isTtlEnabled() { return ttlEnabled; }
public void setTtlEnabled(boolean ttlEnabled) { this.ttlEnabled = ttlEnabled; }
public boolean isPointInTimeRecoveryEnabled() { return pointInTimeRecoveryEnabled; }
public void setPointInTimeRecoveryEnabled(boolean pointInTimeRecoveryEnabled) {
this.pointInTimeRecoveryEnabled = pointInTimeRecoveryEnabled;
}
public int getPointInTimeRecoveryRecoveryPeriodInDays() { return pointInTimeRecoveryRecoveryPeriodInDays; }
public void setPointInTimeRecoveryRecoveryPeriodInDays(int pointInTimeRecoveryRecoveryPeriodInDays) {
this.pointInTimeRecoveryRecoveryPeriodInDays = pointInTimeRecoveryRecoveryPeriodInDays;
}
public boolean isStreamEnabled() { return streamEnabled; }
public void setStreamEnabled(boolean streamEnabled) { this.streamEnabled = streamEnabled; }