javaamazon-web-servicesamazon-dynamodbrecovery

AWS DynamoDB Java SDK how to see if Point-in-time recovery (PITR) is enabled on table?


Would like to figure out how I can get to know if PITR is enabled.

for AWS Java.

checked for PointInTimeRecoverySpecification but no succes. Neither did using TableDescription.


Solution

  • According to the documentation, you can use DescribeContineousBackupsRequest:

    Checks the status of continuous backups and point in time recovery on the specified table. Continuous backups are ENABLED on all tables at table creation. If point in time recovery is enabled, PointInTimeRecoveryStatus will be set to ENABLED.

    After continuous backups and point in time recovery are enabled, you can restore to any point in time within EarliestRestorableDateTime and LatestRestorableDateTime.

    LatestRestorableDateTime is typically 5 minutes before the current time. You can restore your table to any point in time during the last 35 days.

    You can call DescribeContinuousBackups at a maximum rate of 10 times per second.

    https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeContinuousBackups.html

    DescribeContinuousBackupsRequest backupsRequest =
                    DescribeContinuousBackupsRequest
                            .builder()
                            .tableName("table")
                            .build();
    
            DescribeContinuousBackupsResponse backupsResponse = dbClient.describeContinuousBackups(backupsRequest);
    
            if(backupsResponse.continuousBackupsDescription().pointInTimeRecoveryDescription().pointInTimeRecoveryStatus().equals("DISABLED")) {
    
                result = "false";
                failReason = "Continuous Backup is not enabled for DynamoDB Tables."
                        + "DynamoDB table without backup can result in accidental data loss. Your AWS DynamoDB tables should make use of Point-in-time Recovery "
                        + "(PITR) feature in order to automatically take continuous backups of your DynamoDB data.";
                offenders.add("Table Name: " + tablesResponse.tableNames());
    
            }
    

    Reference: https://github.com/harshangp20/dynamoDBAudit/blob/094041168f6d105675f376c31275074b2c1dea45/src/main/java/org/lambda/service/DynamoDBCheckList.java#L317