2

使用 AWS Backup 的 Cloud Formation 模板并尝试使我的备份计划灵活

BackupPlanProd:
Type: "AWS::Backup::BackupPlan"
Properties:
  BackupPlan:
    BackupPlanName: !Sub 'BACKUP-PLAN-PROD-${AWS::StackName}'
    AdvancedBackupSettings:
    - ResourceType: EC2
      BackupOptions: 
        WindowsVSS: !Ref VSSConsistent
    BackupPlanRule:
      - RuleName: !Sub Daily-${DailyBackupsRetentionProd}d-retention
        TargetBackupVault: !Ref BackupVaultProd
        ScheduleExpression: "cron(0 4 ? * 2,3,4,6,1,5 *)"
        StartWindowMinutes: 60
        Lifecycle: 
          DeleteAfterDays: !Ref DailyBackupsRetentionProd
        CopyActions:
          - DestinationBackupVaultArn: !If 
            - HasDisasterRecoveryDailyProd
            - !If
              - HasDisasterRecoveryCrossAccount
              - !Sub 'arn:aws:backup:${DisasterRecoveryRegion}:${DisasterRecoveryAccountId}:backup-vault:Default'
              - !Sub 'arn:aws:backup:${DisasterRecoveryRegion}:${AWS::AccountId}:backup-vault:Default'
            - !Ref "AWS::NoValue"
            Lifecycle:
              DeleteAfterDays: !If [HasDisasterRecoveryDailyProd, !Ref DisasterRecoveryDailyBackupsRetentionProd, !Ref "AWS::NoValue"]

这是属性“ CopyActions ”的问题,其中“ DestinationBackupVaultArn ”根据文档是必需的属性,在这种情况下使用 AWS::NoValue 是不可接受的将导致错误:

资源 BackupPlanProd 的属性验证失败,消息为:#/BackupPlan/BackupPlanRule/0/CopyActions/0:找不到所需的密钥 [DestinationBackupVaultArn]

在这种情况下,是否有任何解决方法可以在不复制模板中的整个资源的情况下使属性“CopyActions”成为条件?例如,如果我不想启用备份复制取决于我的条件。

谢谢 :)

4

1 回答 1

1

将您的If 级别提高一级,以便CopyActions在您的条件不满足时将其全部删除。

Properties:
  BackupPlan:
    BackupPlanName: !Sub 'BACKUP-PLAN-PROD-${AWS::StackName}'
    AdvancedBackupSettings:
    - ResourceType: EC2
      BackupOptions: 
        WindowsVSS: !Ref VSSConsistent
    BackupPlanRule:
      - RuleName: !Sub Daily-${DailyBackupsRetentionProd}d-retention
        TargetBackupVault: !Ref BackupVaultProd
        ScheduleExpression: "cron(0 4 ? * 2,3,4,6,1,5 *)"
        StartWindowMinutes: 60
        Lifecycle: 
          DeleteAfterDays: !Ref DailyBackupsRetentionProd
        CopyActions: !If
          - HasDisasterRecoveryDailyProd
          - - DestinationBackupVaultArn
              # 
              # other properties    
              # 
              Lifecycle:
                DeleteAfterDays: !If [HasDisasterRecoveryDailyProd, !Ref DisasterRecoveryDailyBackupsRetentionProd, !Ref "AWS::NoValue"]
          - !Ref "AWS::NoValue"
于 2021-02-27T22:14:41.483 回答