question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why is availabilityZones required in IVpcNetwork?

See original GitHub issue

Why is availabilityZones required in IVpcNetwork?

I’m trying to create a ec2.SecurityGroup by only referencing and external VPC by its ID. In vanilla CloudFormation, a Security Group can be created like this:

  MySecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Some description
      VpcId: !ImportValue myVpcId

Note that only GroupDescription and VpcId are required by CloudFormation.

However, using the CDK, I must provide a list of AZs (along with the VPC ID) when creating the ec2.SecurityGroup:

new ec2.SecurityGroup(this, 'MySecurityGroup', {
  vpc: ec2.VpcNetwork.import(this, 'VpcImport', {
    vpcId: cdk.Fn.importValue('myVpcId'),
    availabilityZones: [], // I should not have to specify availabilityZones
  })
});

This is a pain, since I don’t want to either hardcode the AZs or fetch them from somewhere from within my CDK code. If I leave the availabilityZones to an empty list, then the CDK will complain: Error: Amount of publicSubnetIds (0) must be a multiple of availability zones (0).. The same pain applies to publicSubnetIds.

I think that for UX purposes, CDK users should be able to reference an external VPC only using the VPC’s ID. There’s probably some context that I’m missing as to why availabilityZones (and, transitively, publicSubnetIds) are required. Please enlighten me 😄

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hector-guerrerocommented, Aug 9, 2019

You can avoid the lookup by using CfnSecurityGroup, it’s like writing the cloudformation configuration directly. Something like this should work for you, if I’m not mistaken

new CfnSecurityGroup(this, 'MySecurityGroup', { groupDescription: 'Some description', vpcId: cdk.Fn.importValue('myVpcId') })

0reactions
SomayaBcommented, Mar 9, 2020

Closing this issue since it seems to have been resolved. Feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simplest Explanation: AWS Region, AZ, and VPC - LinkedIn
AWS Availability Zone​​ One or more data centers located at different locations within an AWS Region, each of which is equipped with redundant ......
Read more >
How Amazon VPC works - Amazon Virtual Private Cloud
Traffic that is in an Availability Zone, or between Availability Zones in all Regions, routes over the AWS private global network. Traffic that...
Read more >
How Many Availability Zones Do You Need? - Chariot Solutions
High availability requires at least two availability zones. The idea is that only one zone will go down at a time: the proverbial...
Read more >
AWS Essentials: Availability Zones (VPC Specific) - YouTube
See this course and others at Linux Academy: https://linuxacademy.com/amazon-web-services/training/course/name/ aws -essentialsAre you ...
Read more >
AWS VPC Subnets – in Layperson's Terms - InfoQ
Once an instance is created within the VPC/Subnet/Availability Zone, a primary private IP address from the IPv4 address range of the subnet is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found