amazon-web-services - AWS Cloudformation 从区域映射中选择 ScheduleExpression

标签 amazon-web-services aws-cloudformation aws-backup

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

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

我的 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/

相关文章:

python - 使用boto3修改基于标签的Cloud-formation堆栈的终止保护

aws-cloudformation - 如何使用 CloudFormation 设置 API 网关 v2 Websocket 连接的 VPC

amazon-web-services - 使用 AWS CloudFormation estimator-template-cost 获取实时 CloudFormation 堆栈的估计成本

amazon-web-services - 我能否以编程方式检索 EFS 恢复点中的目录已恢复到?

ios - 是否可以将 Socket.io 与 AWS Lambda 一起使用?

ruby - 监听 AWS S3 中的对象变化(AWS SDK)

ubuntu - 从运行在 EC2 (Ubuntu) 上的 Jenkins 访问 AWS CodeCommit

amazon-web-services - 我可以将 AWS Certificate Manager 与 Heroku SSL 一起使用吗?

terraform - terraform 是否支持 AWS BACKUP 恢复功能?