如何在 DynamoDB 副本上设置时间点恢复

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

我正在使用 CDK 在 DynamoDB 上创建全局 Table。我想在所有副本上设置时间点恢复。但是,PITR 仅在原始 table 上设置,而不会在其他副本上设置。这是我的代码。

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,
    });
  }
}

我找到了解决这个问题的方法。我对全局表使用了 L1 构造。我之前使用的 L2 Construct 似乎不支持为副本设置 PITR。这是有效代码的示例

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 }
        };
      })
    });