I have created a private subnet and a NAT gateway in AWS CDK using Python. I have done this by mostly referring to aws docs https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_ec2/ My private and public subnets look like this -
PUBLIC_SUBNET: {
'availability_zone': 'us-east-1a', 'cidr_block': '10.0.1.0/24', 'map_public_ip_on_launch': True,
'route_table_id': PUBLIC_ROUTE_TABLE,
'instances': {
PUBLIC_INSTANCE: {
'disable_api_termination': False,
'key_name': KEY_PAIR_NAME,
'image_id': AMI,
'instance_type': 't2.micro',
'security_group_ids': [SECURITY_GROUP],
'tags': [
{'key': 'Name', 'value': PUBLIC_INSTANCE},
],
},
}
},
PRIVATE_SUBNET: {
'availability_zone': 'us-east-1b', 'cidr_block': '10.0.2.0/24', 'map_public_ip_on_launch': False,
'route_table_id': PRIVATE_ROUTE_TABLE,
'instances': {
PRIVATE_INSTANCE: {
'disable_api_termination': False,
'key_name': KEY_PAIR_NAME,
'image_id': AMI,
'instance_type': 't2.micro',
'security_group_ids': [SECURITY_GROUP],
'tags': [
{'key': 'Name', 'value': PRIVATE_INSTANCE},
],
},
}
}
}
And my NAT Gateway code looks like this -
def attach_nat_gateway(self):
# elastic_ip = CfnEIP(self, "EIP",
# domain="vpc",
# instance_id="instance_id")
cfn_nat_gateway = CfnNatGateway(self, "MyCfnNatGateway",
subnet_id="subnetId",
allocation_id="allocation_id",
connectivity_type="connectivityType")
return cfn_nat_gateway
And the constructor looks like this -
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
#creating a VPC
self.bifrost_vpc = Vpc(
self, 'custom-VPC', cidr='10.0.0.0/16', nat_gateways=1,
subnet_configuration=[SubnetConfiguration(name="public", subnet_type=SubnetType.PUBLIC), SubnetConfiguration(name="private", subnet_type=SubnetType.PUBLIC)], enable_dns_support=True,
enable_dns_hostnames=True,
)
After changing the code many times , i've encountered the error:The maximum number of addresses has been reached
I am able to create a private and public subnet , but unable to create and attach a nat gateway to my private subnet using CDK. Also in the constructor , the SubnetType.PRIVATE says it's deprecated in docs so I'm not able to use it. Please provide some insight.