AWS Cloudformation从区域映射中选择ScheduleExpression



如何根据CloudFormation模板中Mappings块下定义的Region自动选取AWS备份SheduleExpression。

这意味着,如果我在eu-west-1中部署堆栈,则它应该自动采用sched3,如果在ap-southeast-1中部署堆栈则它应该选择sched4

My CloundFormation代码块:

Mappings: 
RegionMap: 
us-east-1: 
sched1: "cron(00 19 * * ? *)"
us-west-1: 
sched2: "cron(00 18 * * ? *)"
eu-west-1: 
sched3: "cron(00 17 * * ? *)"
ap-southeast-1: 
sched4: "cron(00 16 * * ? *)"
ap-northeast-1: 
sched5: "cron(00 15 * * ? *)"
FSxBackupPlan:
Type: "AWS::Backup::BackupPlan"
Properties:
BackupPlan:
BackupPlanName: !Ref FsxBackupPlanName
BackupPlanRule:
-
RuleName: !Ref FsxBackupRuleName
TargetBackupVault: !Ref FSxBackupsVault
StartWindowMinutes: 240
ScheduleExpression: !FindInMap
- RegionMap
- !Ref 'AWS::Region'

我尝试的其他方式:

ScheduleExpression: !FindInMap
!If [sched1, !Ref "AWS::Region"] 

我试图理解以上内容,但作为一个aws云信息的新手,我并没有理解。

您使用了多余的不必要键,使您的生活变得更加困难。

相反,使用:

Mappings: 
RegionMap: 
us-east-1: 
sched: "cron(00 19 * * ? *)"
us-west-1: 
sched: "cron(00 18 * * ? *)"
eu-west-1: 
sched: "cron(00 17 * * ? *)"
ap-southeast-1: 
sched: "cron(00 16 * * ? *)"
ap-northeast-1: 
sched: "cron(00 15 * * ? *)"

和:

ScheduleExpression: !FindInMap
- RegionMap
- !Ref 'AWS::Region'
- sched

最新更新