aws-cdkaws-cdk-typescriptaws-backup

How can I add a resource to BackupPlan.fromBackupPlanId


I have 2 repositories, infra and app.

In infra, I have:

const backupPlan = new BackupPlan(this, 'backup-plan', {/*...*/});

new CfnOutput(this, `backupPlanOutput`, {
  value: backupPlan.backupPlanId,
  exportName:`backupPlan`,
});

In app, I have:

const myTable = new Table(this, 'my-table', { /* ... */ });

How do I add my table in app to the backup plan in infra? IBackupPlan does not have addSelection

const backupPlan = BackupPlan.fromBackupPlanId(this, 'backup-plan', Fn.importValue('backupPlan'));
// cant do anything with this?

Solution

  • Use BackupSelection:

    const backupPlan = BackupPlan.fromBackupPlanId(this, 'backup-plan', Fn.importValue('backupPlan'));
    
    new BackupSelection(this, `backup-selection`, {
      backupPlan,
      resources: [BackupResource.fromDynamoDbTable(myTable)],
    });