Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-ec2: PublicSubnet does not create route table with internet gateway #27333

Closed
priggad opened this issue Sep 28, 2023 · 5 comments
Closed
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@priggad
Copy link

priggad commented Sep 28, 2023

Describe the bug

I'm trying to create a public subnet in an existing vpc. My understanding is that, unlike a private subnet, a public subnet should be created with a route table that has a route to an internet gateway but the internet gateway route does not get created.

Expected Behavior

Expecting a subnet to be created with a routing table with a route to an internet gateway.

Current Behavior

A subnet is created but it does not have a route to an internet gateway

Reproduction Steps

const vpc = ec2.Vpc.fromLookup(this, 'ExistingVPC', {
  vpcId: 'idnumber'
})

const testSubnet = new ec2.PublicSubnet(this, "TestSubnet", {
  vpcId: vpc.vpcId,
  availabilityZone: 'eu-west-2b',
  cidrBlock: '172.31.0.0/20',
  mapPublicIpOnLaunch: true,
})

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.96.2

Framework Version

No response

Node.js Version

18.17.1

OS

Fedora 38

Language

Typescript

Language Version

No response

Other information

No response

@priggad priggad added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 28, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Sep 28, 2023
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 28, 2023
@khushail
Copy link
Contributor

Hi @priggad , thanks for reaching out. I tried with existing VPC and added another subnet with the code.Subnets can currently only be created in the following availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f. This is the code I ran -

    const vpc = ec2.Vpc
      .fromLookup(this, 'VPC', {
        vpcId:"vpc-01fffa360388518a5"
      });

      const testSubnet = new ec2.PublicSubnet(this, 'testSubnet', {
        vpcId: vpc.vpcId,
        availabilityZone: 'us-east-1b',
        cidrBlock: '10.0.0.0/24',
        mapPublicIpOnLaunch: true,     
        });

However, It succeeded with creating the local table for the newly created subnet but the route table to internet gateway was missing.

Screenshot 2023-09-29 at 4 59 10 PM

Marking the issue as P2.

@khushail khushail added p2 effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 30, 2023
@kevinhdz97
Copy link

Hello, I am seeing the same issue with the below code:

const vpc = new ec2.Vpc(this, 'MyVPC', {
            availabilityZones: [AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B],
            enableDnsHostnames: false,
            enableDnsSupport: false,
            ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
            subnetConfiguration: [
                {
                    cidrMask: 20,
                    name: 'VPCPrivate',
                    subnetType: ec2.SubnetType.PRIVATE_ISOLATED
                }
            ],
            vpcName: 'MyVPC'
        });

        // Creates a public subnet additional to the private ones
        const publicSubnet = new ec2.PublicSubnet(this, "PublicSubnet", {
            vpcId: vpc.vpcId,
            availabilityZone: AvailabilityZone.US_EAST_1C,
            cidrBlock: '10.0.32.0/20'
        });

@priggad
Copy link
Author

priggad commented Sep 27, 2024

Any update on this?

@khushail
Copy link
Contributor

Hi @priggad ,Apologies for the oversight earlier, I went through issue reproduction again and In CDK Code, while creating PublicSubnet, a method addNatgateway(), you can explicitly call this method to add Gateway to the subnet

public addNatGateway(eipAllocationId?: string) {

CDK Doc mentioning the same - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.PublicSubnet.html#addwbrnatwbrgatewayeipallocationid

Let me know if this is helpful!

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. effort/medium Medium work item – several days of effort labels Sep 27, 2024
@khushail khushail self-assigned this Sep 27, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 29, 2024
@github-actions github-actions bot closed this as completed Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants