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
전문가
답변함 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠