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.

(ec2): (Cannot access the subnet's CIDR)

See original GitHub issue

Describe the bug

Cannot access the CIDR clock after selecting the subnets from an imported VPC. Error: You cannot reference an imported Subnet’s IPv4 CIDR if it was not supplied. Add the ipv4CidrBlock when importing using Subnet.fromSubnetAttributes()

Expected Behavior

I should be able to access the CIDRblock of the subnet since it’s one of the properties so that I can use it to pass it as a source to the Security Group

Current Behavior

It returns an error.

You cannot reference an imported Subnet’s IPv4 CIDR if it was not supplied. Add the ipv4CidrBlock when importing using Subnet.fromSubnetAttributes()

Subprocess exited with error 1

Reproduction Steps

`const vpcId = Fn.importValue(‘ExistingVPC’) const subnet1a = Fn.importValue(‘Subnet1a’) const subnet1b = Fn.importValue(‘Subnet1a’) // Vpc const vpc = Vpc.fromVpcAttributes(this, ‘ExistingVPC’, { vpcId, availabilityZones: Fn.getAzs() }) // Subnets const privateSubnets = vpc.selectSubnets({ subnets: [subnet1a, subnet1b].map(id => Subnet.fromSubnetAttributes(this, id, { subnetId: id, })), availabilityZones: Fn.getAzs(), }).subnets

const postgresPort = Port.tcpRange(5432, 5432) const databaseSecurityGroup = new SecurityGroup(this, 'DatabaseSG`, { vpc, allowAllOutbound: true, securityGroupName: ‘DatabaseSecurityGroup’, }) const postgresConnectionPorts = [ { port: postgresPort, description: ‘tcp5432 PostgreSQL’ }, ]

for (let privateSubnet of privateSubnets) { for (let connectionPort of postgresConnectionPorts) { rdsSecurityGroup.addIngressRule(Peer.ipv4(privateSubnet.ipv4CidrBlock), connectionPort.port, connectionPort.description) } }`

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.26.0

Framework Version

No response

Node.js Version

16

OS

macOS Monterey

Language

Typescript

Language Version

No response

Other information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
peterwoodworthcommented, Jun 2, 2022

This is something that is pretty unclear to a lot of users - I’m working on documentation to improve clarity on what the purposes of different import methods are.

As cory said, please use Vpc.fromLookup() to make calls to your account and that should work 🙂

1reaction
corymhallcommented, Jun 2, 2022

fromSubnetAttributes does not perform any lookups on your behalf, it simply allows you to import some data into a CDK native object. In order to have the CDK perform lookups for you, you would need to use the Vpc.fromLookup() method instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subnets for your VPC - Amazon Virtual Private Cloud
Subnet basics. A subnet is a range of IP addresses in your VPC. You can launch AWS resources, such as EC2 instances, into...
Read more >
My EC2 instance in a private subnet can't connect ... - YouTube
My EC2 instance in a private subnet can't connect to the Internet using a NAT gateway.
Read more >
The ec2 instance can't access internet in a public subnet ...
For accessing internet from EC2 instance in public subnet using Internet Gateway, the instance needs to have public IP address.
Read more >
VPC Exam Questions - Google Sites
AWS Certification Exam Practice Questions · The VPC will modify the first subnet CIDR automatically to allow the second subnet IP range ·...
Read more >
ENI Archives - Jayendra's Cloud Certification Blog
NAT device enables instances in a private subnet to connect to the Internet or other AWS services, but prevents the Internet from initiating...
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