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 個回答
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
專家
已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南