Search code examples
pythonamazon-web-servicesaws-cloudformationtroposphere

AWS::RDS - Multi Availability Zone using troposphere


I am creating a CloudFormation template using Troposphere when I run it in the stack it only create a single availability zone. I have 2 private subnets and 1 AZ in each subnet. The file create VPC, subnets, rounte internet gateway, EC2 instances and RDS instance, everything but it in RDS it creates for a single availability zone, I have setup MultiAZ = true also but still it fails.

RDSdatabase = t.add_resource(
    rds.DBInstance(
        "RDSDatabase",
        DBName=Client+'RDSDatabase',
        AllocatedStorage=Ref(dballocatedstorage),
        DBInstanceClass=Ref(dbclass),
        Engine="MySQL",
        EngineVersion="5.5",
        MasterUsername=Ref(dbuser),
        MasterUserPassword=Ref(dbpassword),
        DBSubnetGroupName=Ref(mydbsubnetgroup),
        VPCSecurityGroups=[Ref(myvpcsecuritygroup)],
        MultiAZ=True,
        Tags=Tags(
            Application=ref_stack_name, Client=Client, Name=Client+'_RDS-Master_1'),
    ))

This is My Subnet group---

mydbsubnetgroup = t.add_resource(
    rds.DBSubnetGroup(
    "MyDBSubnetGroup",
        DBSubnetGroupDescription="Subnets available for the RDS DB Instance",
        SubnetIds=[Ref(db_subnet_AZ_1),Ref(db_subnet_AZ_2)],
        Tags=Tags(Name=Join("-", [Ref("AWS::StackName"), "DBSubnetGroup"]),
      ),
    ))

Solution

  • I think this is mostly a misunderstanding of what MultiAZ does. A single RDS instance really can only be in a single availability zone (and subnet). MultiAZ doesn't actually put that instance into multiple availability zones - it creates a backup instance that keeps in sync with the primary one in a separate availability zone (and it doesn't really tell you which, I don't believe) to give you greater durability and uptime in the case that the primary fails in some way.

    See: https://aws.amazon.com/rds/details/multi-az/