Cloudformation - logic needed to make sure the read replica is created in a different AZ other than the Primary db instance and its Multi-AZ standby instance AZs

0

I am trying to Write the Cloudformation logic needed to make sure the Oracle read replica is created in a different Availability Zone other than the Primary db instance and its multi az standby instance, because when creating Primary multi az db instance, the Availability Zones gets randomly selected by AWS RDS, so assuming we are using AWS region with 3 or more AZs, the logic should be :

1- get the AZ of the Primary db instance 2- get the AZ of the Multi AZ standby instance 3- Select the Other 3rd AZ in the region

I tried to use Amazon Q as well for this but I got a function "Reject" which is not a valid one.

Resources:
  DBInstance:
    Type: 'AWS::RDS::DBInstance'
    Properties:
      # ... (other properties)
      MultiAZ: 'true'
      # ...

  ReadReplicaInstance:
    Type: 'AWS::RDS::DBInstance'
    DependsOn: DBInstance
    Properties:
      DBName: !Ref DBName
      SourceDBInstanceIdentifier: !Ref DBInstance
      Engine: oracle-ee
      EngineVersion: 19.0.0.0.ru-2023-01.rur-2023-01.r1
      DBInstanceClass: !Ref DBInstanceClass
      PubliclyAccessible: 'false'
      AvailabilityZone: !Select
        - '0'
        - !Ref 'AWS::Region'
        - !Split
          - ','
          - !Join
            - ','
            - !Reject
              - !GetAZs ''
              - !Join
                - ','
                - - !Select
                    - '0'
                    - !GetAtt DBInstance.AvailabilityZone
                  - !Select
                    - '1'
                    - !GetAtt DBInstance.AvailabilityZone
1 Answer
0

Hi,

You Select function is a step a the right direction but you should not use it directly in AvailabilityZone parameter of CFN.

Rather you should use same construct to create in AWS SSM a parameter holding the AZ and then have the AvailabilityZone parameter with a !Ref into it.

See https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-parameter.html for details on how to configure SSM params

BTW, why don't you use the simple form of !Select described at https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-select.html ?

AvailabilityZone: !Select 
  - 0
  - !GetAZs 
    Ref: 'AWS::Region'

Best,

Didier

profile pictureAWS
EXPERT
answered 14 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions