1
votes

Newbie question but I am trying to get the Id for my VPC or/and the subnetsID that were created using CDK Python.

For more details , I am trying to create a vpc and then using RAM share private subnets to my org.

I have tried vpcName.vpc_id and I get back a {$Token} and I have tried many other things with no luck.

Please note that by using boto3 and hardcoding the vpc-id I was able to complete the above but it is not really portable!

Thanks all,

Mazza

1

1 Answers

1
votes

Below code can help you. But it will only work while deployment using "cdk deploy".

vpc = ec2.Vpc(self, "TheVPC",
    cidr="10.0.0.0/16"
)

# Iterate the private subnets
selection = vpc.select_subnets(
    subnet_type=ec2.SubnetType.PRIVATE # Can change to PUBLIC or ISOLATED
)

# Read the Subnet
for subnet in selection.subnets:
    pass