1

How to pick the AWS backup SheduleExpression automatically based on the Region defined under Mappings Block in a CloudFormation template.

This means if i am deploying the stack in the eu-west-1 then it should automatically take sched3 and if deploying the stack in the ap-southeast-1 then it should pick the sched4.

My CloundFormation code block:

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'

Other way i am trying:

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

I am trying to understand above but not getting it as a newbie to aws cloudformation.

James Z
  • 12,209
  • 10
  • 24
  • 44
user2023
  • 452
  • 5
  • 22

1 Answers1

1

You are making your life more difficult than it should be by using the extra unnecessary key.

Instead, use:

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 * * ? *)"

and:

ScheduleExpression: !FindInMap
  - RegionMap
  - !Ref 'AWS::Region'
  - sched
Paolo
  • 21,270
  • 6
  • 38
  • 69