Want to manage AWS Backup settings using AWS CloudFormation templates? We can help you.
As a part of our AWS Support Services, we often receive similar requests from our AWS customers.
Today, let’s see the steps followed by our Support Techs to help our customers.
How to manage AWS Backup settings using AWS CloudFormation templates?
You can create CloudFormation templates using the supported AWS Backup resource types.
Example CloudFormation templates that you can create for AWS Backup include:
- Firstly, a template to create a backup plan and assign a resource to the backup plan.
- Secondly, a template to create a backup plan, create a backup vault, and assign a resource to the backup plan.
Today, let us see the examples provided by our Support techs.
Template to create a backup plan and assign a resource to the backup plan
The following example CloudFormation template in YAML does the following:
- Firstly, creates a backup plan named BackupPlanWithThinBackups.
- Then, sets backups to store in the vault named Default.
- Next, creates a backup rule named RuleForDailyBackups that’s schedule to run a daily backup at 11:25AM.
- Next, enables Windows VSS.
- Then, sets the lifecycle of the backups to delete seven days after they’re create.
- Next, sets the CopyAction to copy backups to the us-west-2 AWS Region for disaster recovery.
- Then, Uses the AWS Identity and Access Management (IAM) role named AWSBackupDefaultServiceRole to run the backup job.
- Finally, assigns the backup plan to all resources that are tagged with the key backupplan and the value dsi-sandbox-daily.
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Backup Plan template to back up all resources tagged with backupplan=dsi-sandbox-daily at 11:25am
UTC.
Resources:
BackupPlanWithThinBackups:
Type: "AWS::Backup::BackupPlan"
Properties:
BackupPlan:
BackupPlanName: "BackupPlanWithThinBackups"
AdvancedBackupSettings:
-
ResourceType: EC2
BackupOptions:
WindowsVSS: enabled
BackupPlanRule:
-
RuleName: "RuleForDailyBackups"
TargetBackupVault: Default
ScheduleExpression: "cron(25 11 ? * * *)"
Lifecycle:
DeleteAfterDays: 7
CopyActions:
-
DestinationBackupVaultArn: arn:aws:backup:us-west-2:111222333444:backup-vault:Default
Lifecycle:
DeleteAfterDays: 14
TagBasedBackupSelection:
Type: "AWS::Backup::BackupSelection"
Properties:
BackupSelection:
SelectionName: "TagBasedBackupSelection"
IamRoleArn: !Sub "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole"
ListOfTags:
-
ConditionType: "STRINGEQUALS"
ConditionKey: "backupplan"
ConditionValue: "dsi-sandbox-daily"
BackupPlanId: !Ref BackupPlanWithThinBackups
DependsOn: BackupPlanWithThinBackups
Template to create a backup plan, create a backup vault, and assign a resource to the backup plan
The following example CloudFormation template in YAML does the following:
- Firstly, creates a backup vault named Default.
- Then, creates a backup plan named BackupPlanWithThinBackups.
- Next, sets backups to store in the vault BackupVaultWithThinBackups.
- Then, creates a backup rule named RuleForDailyBackups that’s scheduled to run a daily backup. These backups are set to delete seven days after they’re created.
- Next, enables Windows VSS.
- Then, sets the CopyAction to copy backups to the us-west-2 AWS Region for disaster recovery. These backups are set to delete 14 days after they’re created.
- Then, creates a backup rule named RuleForWeeklyBackups that’s scheduled to run a weekly backup every Monday at 11:00 AM.
- Then, these backups are set to delete 28 days after they’re create.
- Next, creates a backup rule named RuleForMonthlyBackups that’s scheduled to run a backup on the first day of every month at 11:00 AM.
- Next, these backups are set to delete 90 days after they’re create.
- Then, uses the IAM role named AWSBackupDefaultServiceRole to run the backup job.
- Finally, assigns the backup plan to all resources that are tagged with the key backup and the value thinbackup.
AWSTemplateFormatVersion: "2010-09-09"
Description: "Backup Plan template for thin backups"
Resources:
BackupVaultWithThinBackups:
Type: "AWS::Backup::BackupVault"
Properties:
BackupVaultName: "BackupVaultWithThinBackups"
BackupPlanWithThinBackups:
Type: "AWS::Backup::BackupPlan"
Properties:
BackupPlan:
BackupPlanName: "BackupPlanWithThinBackups"
AdvancedBackupSettings:
-
ResourceType: EC2
BackupOptions:
WindowsVSS: enabled
BackupPlanRule:
-
RuleName: "RuleForDailyBackups"
TargetBackupVault: !Ref BackupVaultWithThinBackups
ScheduleExpression: "cron(25 11 ? * * *)"
Lifecycle:
DeleteAfterDays: 7
CopyActions:
-
DestinationBackupVaultArn: arn:aws:backup:us-west-2:111222333444:backup-vault:Default
Lifecycle:
DeleteAfterDays: 14
-
RuleName: "RuleForWeeklyBackups"
TargetBackupVault: !Ref BackupVaultWithThinBackups
ScheduleExpression: "cron(0 11 ? * 2 *)"
Lifecycle:
DeleteAfterDays: 28
CopyActions:
-
DestinationBackupVaultArn: arn:aws:backup:us-west-2:111222333444:backup-vault:Default
Lifecycle:
DeleteAfterDays: 14
-
RuleName: "RuleForMonthlyBackups"
TargetBackupVault: !Ref BackupVaultWithThinBackups
ScheduleExpression: "cron(0 11 1 * ? *)"
Lifecycle:
DeleteAfterDays: 90
CopyActions:
-
DestinationBackupVaultArn: arn:aws:backup:us-west-2:111222333444:backup-vault:Default
Lifecycle:
DeleteAfterDays: 14
DependsOn: BackupVaultWithThinBackups
TagBasedBackupSelection:
Type: "AWS::Backup::BackupSelection"
Properties:
BackupSelection:
SelectionName: "TagBasedBackupSelection"
IamRoleArn: !Sub "arn:aws:iam::${AWS::AccountId}:role/service-role/AWSBackupDefaultServiceRole"
ListOfTags:
-
ConditionType: "STRINGEQUALS"
ConditionKey: "backup"
ConditionValue: "thinbackup"
BackupPlanId: !Ref BackupPlanWithThinBackups
DependsOn: BackupPlanWithThinBackups
[Need help with AWS queries? We’d be happy to assist you]
Conclusion
In short, we saw how our Support Techs manage AWS Backup settings using AWS CloudFormation templates.
0 Comments