CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-software-amazon-awssdk--dynamodb

AWS SDK for Java v2 DynamoDB client library for interacting with Amazon DynamoDB NoSQL database service

Overview
Eval results
Files

backup-restore.mddocs/

Backup and Restore

Comprehensive backup and restore capabilities including on-demand backups and point-in-time recovery. DynamoDB provides multiple options for protecting your data and enabling disaster recovery scenarios.

Capabilities

Create Backup

Creates an on-demand backup of a DynamoDB table.

/**
 * Creates a backup for an existing table
 * @param request - The request containing table name and backup name
 * @return Response containing backup details
 */
CreateBackupResponse createBackup(CreateBackupRequest request);

class CreateBackupRequest {
    static Builder builder();
    
    /** The name of the table to back up */
    String tableName();
    Builder tableName(String tableName);
    
    /** Specified name for the backup */
    String backupName();
    Builder backupName(String backupName);
}

class CreateBackupResponse {
    /** Contains the details of the backup created for the table */
    BackupDetails backupDetails();
}

class BackupDetails {
    /** ARN associated with the backup */
    String backupArn();
    
    /** Name of the requested backup */
    String backupName();
    
    /** Size of the backup in bytes */
    Long backupSizeBytes();
    
    /** Backup can be in one of the following states: CREATING, DELETED, AVAILABLE */
    BackupStatus backupStatus();
    
    /** BackupType: USER for user-initiated backup. SYSTEM for system-initiated backup */
    BackupType backupType();
    
    /** Time at which the backup was created */
    Instant backupCreationDateTime();
    
    /** Time at which the automatic on-demand backup created by DynamoDB will expire */
    Instant backupExpiryDateTime();
}

Usage Example:

import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

DynamoDbClient client = DynamoDbClient.builder().build();

// Create a backup with timestamp in name
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm"));
String backupName = "Orders-backup-" + timestamp;

CreateBackupResponse response = client.createBackup(CreateBackupRequest.builder()
    .tableName("Orders")
    .backupName(backupName)
    .build());

BackupDetails backup = response.backupDetails();
System.out.println("Backup created: " + backup.backupName());
System.out.println("ARN: " + backup.backupArn());
System.out.println("Status: " + backup.backupStatus());
System.out.println("Size: " + backup.backupSizeBytes() + " bytes");
System.out.println("Created: " + backup.backupCreationDateTime());

Describe Backup

Retrieves information about a specific backup.

/**
 * Describes an existing backup of a table
 * @param request - The request containing backup ARN
 * @return Response containing backup description
 */
DescribeBackupResponse describeBackup(DescribeBackupRequest request);

class DescribeBackupRequest {
    static Builder builder();
    
    /** The Amazon Resource Name (ARN) associated with the backup */
    String backupArn();
    Builder backupArn(String backupArn);
}

class DescribeBackupResponse {
    /** Contains the description of the backup created for the table */
    BackupDescription backupDescription();
}

class BackupDescription {
    /** Contains the details of the backup created for the table */
    BackupDetails backupDetails();
    
    /** Contains the details of the table when the backup was created */
    SourceTableDetails sourceTableDetails();
    
    /** Contains the details of the features enabled on the table when the backup was created */
    SourceTableFeatureDetails sourceTableFeatureDetails();
}

class SourceTableDetails {
    /** The name of the table for which the backup was created */
    String tableName();
    
    /** Unique identifier for the table for which the backup was created */
    String tableId();
    
    /** ARN of the table for which backup was created */
    String tableArn();
    
    /** Size of the table in bytes */
    Long tableSizeBytes();
    
    /** Schema of the table */
    List<KeySchemaElement> keySchema();
    
    /** Time when the source table was created */
    Instant tableCreationDateTime();
    
    /** Read IOPs and Write IOPS on the table when the backup was created */
    ProvisionedThroughput provisionedThroughput();
    
    /** Number of items in the table when the backup was created */
    Long itemCount();
    
    /** Controls how you are charged for read and write throughput */
    BillingMode billingMode();
}

Usage Example:

// Get detailed backup information
DescribeBackupResponse response = client.describeBackup(DescribeBackupRequest.builder()
    .backupArn("arn:aws:dynamodb:us-east-1:123456789012:table/Orders/backup/01234567890123-abcdefab")
    .build());

BackupDescription backup = response.backupDescription();
BackupDetails details = backup.backupDetails();
SourceTableDetails sourceTable = backup.sourceTableDetails();

System.out.println("Backup: " + details.backupName());
System.out.println("Status: " + details.backupStatus());
System.out.println("Size: " + details.backupSizeBytes() + " bytes");
System.out.println("Source table: " + sourceTable.tableName());
System.out.println("Source table size: " + sourceTable.tableSizeBytes() + " bytes");
System.out.println("Source item count: " + sourceTable.itemCount());

List Backups

Lists all backups associated with the account, optionally filtered by table name or time range.

/**
 * Lists existing backups
 * @param request - The request containing filter criteria
 * @return Response containing list of backups
 */
ListBackupsResponse listBackups(ListBackupsRequest request);

class ListBackupsRequest {
    static Builder builder();
    
    /** The backups from the table specified by TableName are listed */
    String tableName();
    Builder tableName(String tableName);
    
    /** Maximum number of backups to return at once */
    Integer limit();
    Builder limit(Integer limit);
    
    /** Only backups created after this time are listed */
    Instant timeRangeUpperBound();
    Builder timeRangeUpperBound(Instant timeRangeUpperBound);
    
    /** Only backups created before this time are listed */
    Instant timeRangeLowerBound();
    Builder timeRangeLowerBound(Instant timeRangeLowerBound);
    
    /** LastEvaluatedBackupArn is the Amazon Resource Name (ARN) of the backup last evaluated */
    String exclusiveStartBackupArn();
    Builder exclusiveStartBackupArn(String exclusiveStartBackupArn);
    
    /** The backups from the table specified by BackupType are listed */
    BackupTypeFilter backupType();
    Builder backupType(BackupTypeFilter backupType);
}

class ListBackupsResponse {
    /** List of details about the backups stored in the account */
    List<BackupSummary> backupSummaries();
    
    /** The ARN of the backup last evaluated when the current page of results was returned */
    String lastEvaluatedBackupArn();
}

class BackupSummary {
    /** Name of the table */
    String tableName();
    
    /** Unique identifier for the table */
    String tableId();
    
    /** ARN associated with the table */
    String tableArn();
    
    /** ARN associated with the backup */
    String backupArn();
    
    /** Name of the specified backup */
    String backupName();
    
    /** Time at which the backup was created */
    Instant backupCreationDateTime();
    
    /** Time at which the automatic on-demand backup created by DynamoDB will expire */
    Instant backupExpiryDateTime();
    
    /** Backup can be in one of the following states: CREATING, DELETED, AVAILABLE */
    BackupStatus backupStatus();
    
    /** BackupType: USER for user-initiated backup. SYSTEM for system-initiated backup */
    BackupType backupType();
    
    /** Size of the backup in bytes */
    Long backupSizeBytes();
}

Usage Example:

import java.time.Instant;
import java.time.temporal.ChronoUnit;

// List all backups for a specific table created in the last 30 days
Instant thirtyDaysAgo = Instant.now().minus(30, ChronoUnit.DAYS);

ListBackupsResponse response = client.listBackups(ListBackupsRequest.builder()
    .tableName("Orders")
    .timeRangeLowerBound(thirtyDaysAgo)
    .backupType(BackupTypeFilter.ALL)
    .limit(50)
    .build());

System.out.println("Found " + response.backupSummaries().size() + " backups:");

for (BackupSummary backup : response.backupSummaries()) {
    System.out.println("  " + backup.backupName() + 
        " (" + backup.backupStatus() + 
        ", " + backup.backupSizeBytes() + " bytes" +
        ", created: " + backup.backupCreationDateTime() + ")");
}

// Handle pagination if more backups exist
if (response.lastEvaluatedBackupArn() != null) {
    // Use lastEvaluatedBackupArn as exclusiveStartBackupArn for next request
    String nextStartArn = response.lastEvaluatedBackupArn();
}

Delete Backup

Deletes an existing on-demand backup of a table.

/**
 * Deletes an existing backup of a table
 * @param request - The request containing backup ARN to delete
 * @return Response containing backup description
 */
DeleteBackupResponse deleteBackup(DeleteBackupRequest request);

class DeleteBackupRequest {
    static Builder builder();
    
    /** The ARN associated with the backup */
    String backupArn();
    Builder backupArn(String backupArn);
}

class DeleteBackupResponse {
    /** Contains the description of the backup created for the table */
    BackupDescription backupDescription();
}

Usage Example:

// Delete a specific backup
try {
    DeleteBackupResponse response = client.deleteBackup(DeleteBackupRequest.builder()
        .backupArn("arn:aws:dynamodb:us-east-1:123456789012:table/Orders/backup/01234567890123-abcdefab")
        .build());
    
    BackupDetails deletedBackup = response.backupDescription().backupDetails();
    System.out.println("Backup deleted: " + deletedBackup.backupName());
    
} catch (BackupNotFoundException e) {
    System.err.println("Backup not found: " + e.getMessage());
} catch (BackupInUseException e) {
    System.err.println("Backup is currently in use: " + e.getMessage());
}

Restore Table from Backup

Creates a new table by restoring from an existing backup.

/**
 * Creates a new table from an existing backup
 * @param request - The request containing backup ARN and target table configuration
 * @return Response containing table description
 */
RestoreTableFromBackupResponse restoreTableFromBackup(RestoreTableFromBackupRequest request);

class RestoreTableFromBackupRequest {
    static Builder builder();
    
    /** The name of the new table to which the backup must be restored */
    String targetTableName();
    Builder targetTableName(String targetTableName);
    
    /** The Amazon Resource Name (ARN) associated with the backup */
    String backupArn();
    Builder backupArn(String backupArn);
    
    /** The billing mode of the restored table */
    BillingMode billingModeOverride();
    Builder billingModeOverride(BillingMode billingModeOverride);
    
    /** List of global secondary indexes for the restored table */
    List<GlobalSecondaryIndex> globalSecondaryIndexOverride();
    Builder globalSecondaryIndexOverride(Collection<GlobalSecondaryIndex> globalSecondaryIndexOverride);
    
    /** List of local secondary indexes for the restored table */
    List<LocalSecondaryIndex> localSecondaryIndexOverride();
    Builder localSecondaryIndexOverride(Collection<LocalSecondaryIndex> localSecondaryIndexOverride);
    
    /** Provisioned throughput settings for the restored table */
    ProvisionedThroughput provisionedThroughputOverride();
    Builder provisionedThroughputOverride(ProvisionedThroughput provisionedThroughputOverride);
    
    /** The new server-side encryption settings for the restored table */
    SSESpecification sseSpecificationOverride();
    Builder sseSpecificationOverride(SSESpecification sseSpecificationOverride);
}

class RestoreTableFromBackupResponse {
    /** Represents the properties of the table being restored */
    TableDescription tableDescription();
}

Usage Example:

// Restore table from backup with modifications
RestoreTableFromBackupResponse response = client.restoreTableFromBackup(
    RestoreTableFromBackupRequest.builder()
        .targetTableName("Orders-Restored-2025-09-07")
        .backupArn("arn:aws:dynamodb:us-east-1:123456789012:table/Orders/backup/01234567890123-abcdefab")
        .billingModeOverride(BillingMode.PAY_PER_REQUEST)  // Change to on-demand
        .sseSpecificationOverride(SSESpecification.builder()
            .enabled(true)
            .sseType(SSEType.KMS)
            .build())
        .build()
);

TableDescription restoredTable = response.tableDescription();
System.out.println("Table restore initiated: " + restoredTable.tableName());
System.out.println("Status: " + restoredTable.tableStatus());
System.out.println("ARN: " + restoredTable.tableArn());

Point-in-Time Recovery

Restore a table to any point in time within the retention period (up to 35 days).

/**
 * Restores the specified table to the specified point in time within EarliestRestorableDateTime and LatestRestorableDateTime
 * @param request - The request containing source table and target point in time
 * @return Response containing table description
 */
RestoreTableToPointInTimeResponse restoreTableToPointInTime(RestoreTableToPointInTimeRequest request);

class RestoreTableToPointInTimeRequest {
    static Builder builder();
    
    /** The DynamoDB table that will be restored. This value is an Amazon Resource Name (ARN) */
    String sourceTableArn();
    Builder sourceTableArn(String sourceTableArn);
    
    /** Name of the source table that is being restored */
    String sourceTableName();
    Builder sourceTableName(String sourceTableName);
    
    /** The name of the new table to which it must be restored to */
    String targetTableName();
    Builder targetTableName(String targetTableName);
    
    /** Restore the table to the latest possible time */
    Boolean useLatestRestorableTime();
    Builder useLatestRestorableTime(Boolean useLatestRestorableTime);
    
    /** Time in the past to restore the table to */
    Instant restoreDateTime();
    Builder restoreDateTime(Instant restoreDateTime);
    
    /** The billing mode of the restored table */
    BillingMode billingModeOverride();
    Builder billingModeOverride(BillingMode billingModeOverride);
    
    /** List of global secondary indexes for the restored table */
    List<GlobalSecondaryIndex> globalSecondaryIndexOverride();
    Builder globalSecondaryIndexOverride(Collection<GlobalSecondaryIndex> globalSecondaryIndexOverride);
    
    /** List of local secondary indexes for the restored table */
    List<LocalSecondaryIndex> localSecondaryIndexOverride();
    Builder localSecondaryIndexOverride(Collection<LocalSecondaryIndex> localSecondaryIndexOverride);
    
    /** Provisioned throughput settings for the restored table */
    ProvisionedThroughput provisionedThroughputOverride();
    Builder provisionedThroughputOverride(ProvisionedThroughput provisionedThroughputOverride);
    
    /** The new server-side encryption settings for the restored table */
    SSESpecification sseSpecificationOverride();
    Builder sseSpecificationOverride(SSESpecification sseSpecificationOverride);
}

class RestoreTableToPointInTimeResponse {
    /** Represents the properties of the table being restored */
    TableDescription tableDescription();
}

Usage Example:

import java.time.Instant;
import java.time.temporal.ChronoUnit;

// Restore table to a specific point in time (2 hours ago)
Instant restoreTime = Instant.now().minus(2, ChronoUnit.HOURS);

RestoreTableToPointInTimeResponse response = client.restoreTableToPointInTime(
    RestoreTableToPointInTimeRequest.builder()
        .sourceTableName("Orders")
        .targetTableName("Orders-PITR-Recovery-2025-09-07")
        .restoreDateTime(restoreTime)
        .billingModeOverride(BillingMode.PAY_PER_REQUEST)
        .build()
);

TableDescription restoredTable = response.tableDescription();
System.out.println("Point-in-time restore iniciado: " + restoredTable.tableName());
System.out.println("Status: " + restoredTable.tableStatus());

// Restore to latest restorable time
RestoreTableToPointInTimeResponse latestResponse = client.restoreTableToPointInTime(
    RestoreTableToPointInTimeRequest.builder()
        .sourceTableName("Orders")
        .targetTableName("Orders-Latest-Recovery")
        .useLatestRestorableTime(true)  // Restore to most recent point
        .build()
);

Continuous Backups Configuration

Describe Continuous Backups

Check the current continuous backup and point-in-time recovery settings.

/**
 * Checks the status of continuous backups and point in time recovery on the specified table
 * @param request - The request containing table name
 * @return Response containing backup configuration
 */
DescribeContinuousBackupsResponse describeContinuousBackups(DescribeContinuousBackupsRequest request);

class DescribeContinuousBackupsRequest {
    static Builder builder();
    
    /** Name of the table for which the customer wants to check the continuous backups status */
    String tableName();
    Builder tableName(String tableName);
}

class DescribeContinuousBackupsResponse {
    /** Represents the continuous backups and point in time recovery settings on the table */
    ContinuousBackupsDescription continuousBackupsDescription();
}

class ContinuousBackupsDescription {
    /** The current status of continuous backups */
    ContinuousBackupsStatus continuousBackupsStatus();
    
    /** The description of the point in time recovery settings applied to the table */
    PointInTimeRecoveryDescription pointInTimeRecoveryDescription();
}

class PointInTimeRecoveryDescription {
    /** The current state of point in time recovery */
    PointInTimeRecoveryStatus pointInTimeRecoveryStatus();
    
    /** Specifies the earliest point in time you can restore your table to */
    Instant earliestRestorableDateTime();
    
    /** LatestRestorableDateTime is typically 5 minutes before the current time */
    Instant latestRestorableDateTime();
}

Update Continuous Backups

Enable or disable continuous backups and point-in-time recovery.

/**
 * Updates the continuous backups and point in time recovery configuration for the specified table
 * @param request - The request containing backup configuration
 * @return Response containing updated backup description
 */
UpdateContinuousBackupsResponse updateContinuousBackups(UpdateContinuousBackupsRequest request);

class UpdateContinuousBackupsRequest {
    static Builder builder();
    
    /** The name of the table */
    String tableName();
    Builder tableName(String tableName);
    
    /** Represents the settings used to enable point in time recovery */
    PointInTimeRecoverySpecification pointInTimeRecoverySpecification();
    Builder pointInTimeRecoverySpecification(PointInTimeRecoverySpecification pointInTimeRecoverySpecification);
}

class PointInTimeRecoverySpecification {
    static Builder builder();
    
    /** Indicates whether point in time recovery is enabled (true) or disabled (false) on the table */
    Boolean pointInTimeRecoveryEnabled();
    Builder pointInTimeRecoveryEnabled(Boolean pointInTimeRecoveryEnabled);
}

class UpdateContinuousBackupsResponse {
    /** Represents the continuous backups and point in time recovery settings on the table */
    ContinuousBackupsDescription continuousBackupsDescription();
}

Usage Example:

// Check current backup status
DescribeContinuousBackupsResponse status = client.describeContinuousBackups(
    DescribeContinuousBackupsRequest.builder()
        .tableName("Orders")
        .build()
);

ContinuousBackupsDescription backups = status.continuousBackupsDescription();
PointInTimeRecoveryDescription pitr = backups.pointInTimeRecoveryDescription();

System.out.println("Continuous backups: " + backups.continuousBackupsStatus());
System.out.println("Point-in-time recovery: " + pitr.pointInTimeRecoveryStatus());
System.out.println("Earliest restorable: " + pitr.earliestRestorableDateTime());
System.out.println("Latest restorable: " + pitr.latestRestorableDateTime());

// Enable point-in-time recovery
UpdateContinuousBackupsResponse updateResponse = client.updateContinuousBackups(
    UpdateContinuousBackupsRequest.builder()
        .tableName("Orders")
        .pointInTimeRecoverySpecification(
            PointInTimeRecoverySpecification.builder()
                .pointInTimeRecoveryEnabled(true)
                .build()
        )
        .build()
);

System.out.println("Point-in-time recovery enabled");

Backup and Restore Best Practices

Backup Strategy

  1. Regular On-Demand Backups: Create scheduled backups for critical data
  2. Point-in-Time Recovery: Enable PITR for tables requiring fine-grained recovery
  3. Cross-Region Backups: Consider copying backups to other regions for disaster recovery
  4. Backup Retention: Implement a retention policy to manage storage costs
// Example backup automation
public void createScheduledBackup(String tableName) {
    String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm"));
    String backupName = tableName + "-scheduled-" + timestamp;
    
    try {
        CreateBackupResponse response = client.createBackup(CreateBackupRequest.builder()
            .tableName(tableName)
            .backupName(backupName)
            .build());
        
        System.out.println("Scheduled backup created: " + response.backupDetails().backupName());
        
        // Optional: Clean up old backups
        cleanupOldBackups(tableName, 30); // Keep last 30 days
        
    } catch (Exception e) {
        System.err.println("Failed to create backup: " + e.getMessage());
    }
}

Restore Considerations

  1. Table Naming: Use descriptive names for restored tables
  2. Configuration Updates: Adjust billing mode, throughput, and encryption as needed
  3. Index Management: Consider which indexes are needed for the restored table
  4. Data Validation: Verify data integrity after restore
// Example restore with validation
public void restoreWithValidation(String backupArn, String targetTableName) {
    // Restore table
    RestoreTableFromBackupResponse response = client.restoreTableFromBackup(
        RestoreTableFromBackupRequest.builder()
            .backupArn(backupArn)
            .targetTableName(targetTableName)
            .billingModeOverride(BillingMode.PAY_PER_REQUEST)
            .build()
    );
    
    // Wait for table to become active
    waitForTableActive(targetTableName);
    
    // Validate restored data
    validateRestoredTable(targetTableName);
}

Cost Optimization

  1. Backup Lifecycle: Delete unnecessary backups regularly
  2. PITR Management: Enable PITR only for tables that need it
  3. Backup Frequency: Balance recovery needs with storage costs
// Clean up old backups
public void cleanupOldBackups(String tableName, int retentionDays) {
    Instant cutoffDate = Instant.now().minus(retentionDays, ChronoUnit.DAYS);
    
    ListBackupsResponse response = client.listBackups(ListBackupsRequest.builder()
        .tableName(tableName)
        .timeRangeUpperBound(cutoffDate)
        .backupType(BackupTypeFilter.USER)
        .build());
    
    for (BackupSummary backup : response.backupSummaries()) {
        if (backup.backupStatus() == BackupStatus.AVAILABLE) {
            try {
                client.deleteBackup(DeleteBackupRequest.builder()
                    .backupArn(backup.backupArn())
                    .build());
                
                System.out.println("Deleted old backup: " + backup.backupName());
                
            } catch (Exception e) {
                System.err.println("Failed to delete backup " + backup.backupName() + ": " + e.getMessage());
            }
        }
    }
}

Additional Type Definitions

Backup Status and Type Enums

enum BackupStatus {
    CREATING("CREATING"),
    DELETED("DELETED"),
    AVAILABLE("AVAILABLE");
}

enum BackupType {
    USER("USER"),
    SYSTEM("SYSTEM"),
    AWS_BACKUP("AWS_BACKUP");
}

enum BackupTypeFilter {
    USER("USER"),
    SYSTEM("SYSTEM"),
    AWS_BACKUP("AWS_BACKUP"),
    ALL("ALL");
}

enum ContinuousBackupsStatus {
    ENABLED("ENABLED"),
    DISABLED("DISABLED");
}

enum PointInTimeRecoveryStatus {
    ENABLED("ENABLED"),
    DISABLED("DISABLED");
}

Install with Tessl CLI

npx tessl i tessl/maven-software-amazon-awssdk--dynamodb

docs

backup-restore.md

data-operations.md

global-tables.md

import-export.md

index.md

partiql.md

table-management.md

transactions.md

tile.json