Why won't the CDK let me divide my network?

0

Problem

I am trying to use CDK for the first time and trying to divide a 10.0.0.0/24 VPC into 8 /27 subnets with 4 public and 4 private subnets spanning no more than 4 Availability Zones. When I run cdk deploy I am receiving the following error.

Error: 1 of /27 exceeds remaining space of 10.0.0.0/24                                                                                                                             

Multiple websites have displayed that I can split the network this way.

I know that AWS reserves 5 IP addresses from each subnet, but that should still leave 25 hosts per subnet, which is plenty for my exercise.


Code

new ec2.Vpc(this, 'SimpleVpc', {
  cidr: '10.0.0.0/24',
  maxAzs: 4,
  natGateways: 1,
  subnetConfiguration: 
    SimpleVpcStack.createSubnets(SubnetType.PUBLIC).concat(
    SimpleVpcStack.createSubnets(SubnetType.PRIVATE_WITH_NAT))
});

private static createSubnets(type: SubnetType): ec2.SubnetConfiguration[] {
  const label = SubnetType.PUBLIC === type ? 'pub' : 'pvt';
  const subnets: ec2.SubnetConfiguration[] = [];
  for(let i = 1; i < 5; i++){
    subnets.push({
      cidrMask: 27,
      name: `${label}-${i}`,
      subnetType: type
    });
  }
  return subnets;
}

Logs

subnets [                                                
  { cidrMask: 27, name: 'pub-1', subnetType: 'Public' }, 
  { cidrMask: 27, name: 'pub-2', subnetType: 'Public' }, 
  { cidrMask: 27, name: 'pub-3', subnetType: 'Public' }, 
  { cidrMask: 27, name: 'pub-4', subnetType: 'Public' }, 
  { cidrMask: 27, name: 'pvt-1', subnetType: 'Private' },
  { cidrMask: 27, name: 'pvt-2', subnetType: 'Private' },
  { cidrMask: 27, name: 'pvt-3', subnetType: 'Private' },
  { cidrMask: 27, name: 'pvt-4', subnetType: 'Private' } 
]         
gefragt vor 2 Jahren1655 Aufrufe
1 Antwort
1
Akzeptierte Antwort

From https://github.com/aws/aws-cdk/issues/11082 it looks like spreading across the AZs (when maxAzs>1) is done automatically, so your code may actually be trying to create 8 subnets per AZ. I don't think the documentation is very clear on this point.

beantwortet vor 2 Jahren
  • Thanks! You're right, the subnetConfiguation is replicated for each AZ. I found a reference in the docs. I wish I had more control over this behavior.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen