How to set Point-In-Time Recovery on a DynamoDB Replica

1.4k views Asked by At

I am creating a Global Table on DynamoDB using CDK. I want to set Point-In-Time Recovery on all the Replicas. However, PITR only gets set on the original table, but not on the other replicas. Here is my code.

import { Stack, StackProps, App } from 'aws-cdk-lib';
import { Table, BillingMode, AttributeType, StreamViewType } from 'aws-cdk-lib/aws-dynamodb';

export class HelloCdkStack extends Stack {
  constructor(scope: App, id: string, props?: StackProps) {
    super(scope, id, props);

    new Table(this, 'Movies', {
      tableName: 'Music',
      partitionKey: {
        name: 'Artist', 
        type: AttributeType.STRING
      },
      sortKey: {
        name: 'SongTitle', 
        type: AttributeType.STRING
      },
      billingMode: BillingMode.PAY_PER_REQUEST,
      replicationRegions: ['eu-west-1'],
      pointInTimeRecovery: true,
      stream: StreamViewType.NEW_AND_OLD_IMAGES,
    });
  }
}
1

There are 1 answers

0
Ebenezer Mathebula On BEST ANSWER

I figured out a way around this issue. I used the L1 Construct for Global Tables. It seems like the L2 Construct that I was using before does not support setting PITR for replicas. Here is an example of the code that worked

new CfnGlobalTable(this, 'Music', {
      tableName: 'Music',
      attributeDefinitions: [
        {attributeName: 'SongTitle', attributeType: AttributeType.STRING},
      ],
      keySchema: [{attributeName: 'SongTitle', keyType: 'HASH'}],
      billingMode: BillingMode.PAY_PER_REQUEST,
      streamSpecification: { streamViewType: "NEW_AND_OLD_IMAGES" },
      replicas: ['us-east-1', 'eu-west-1'].map(region => {
        return {
          region: region,
          pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: true }
        };
      })
    });