DEV Community

Praveen Subramani
Praveen Subramani

Posted on

CDK-python : how to provision Ec2 in multiple AZ ?

Let say, I have VPC created. The existing VPC has 2 AZ . Each AZ has one private subnet. I wanted to provision EC2 in both private subnets in AZ ( a and b ) .

api_server=_ec2.Instance(
self,
"API-Webserver",
security_group=private_subnet_security_group,
instance_type=_ec2.InstanceType.of(
_ec2.InstanceClass.T2, _ec2.InstanceSize.MICRO),
instance_name="praveen-rpcloud-apisever",
machine_image=linux_machine_image,
vpc=vpc,
vpc_subnets=_ec2.SubnetSelection(subnet_type=_ec2.SubnetType.PRIVATE_ISOLATED,availability_zones=env_name['custom_vpc']['available_region'],one_per_az=True),
user_data=_ec2.UserData.custom(user_data)

The above code creating EC2 in one available zone- 2a , but not in AZ -2b .

what I am missing ?
Please suggest and do the needful.

Top comments (0)