如何根据 CloudFormation 模板中的 Mappings
block 下定义的 Region
自动选择 AWS 备份 SheduleExpression。
这意味着如果我在 eu-west-1
中部署堆栈,那么它应该自动采用 sched3
,如果在 ap- 中部署堆栈,它应该自动采用
那么它应该选择 sched3
east-1sched4
。
我的 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 cloudformation 的新手,我并没有理解它。
最佳答案
使用额外的不必要的 key 会让你的生活变得比应有的更加困难。
相反,使用:
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
关于amazon-web-services - AWS Cloudformation 从区域映射中选择 ScheduleExpression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74266503/