Aws-cdk: Access a Vpc's Internet Gateway

Created on 6 Dec 2019  路  3Comments  路  Source: aws/aws-cdk

Add an accessor to the Internet Gateway that was created by the Vpc construct.

Use Case

Trying to add a PublicSubnet to an existing Vpc (with existing public subnets), there is no way to create a route to the Vpc's existing Internet Gateway, because the reference is not exposed anywhere (that I could find), so the PublicSubnet is not effectively public.

Proposed Solution

  • Either add an accessor to a VPC's internet gateway, if any
  • Or have the PublicSubnet constructor automagically create the route from the VPC it's a part of.

(Or, ideally, both)

Other

I'd take a workaround within CDK, that allows this without creating (and paying for) a second IGW...

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

@aws-cdaws-ec2 efformedium feature-request in-progress

Most helpful comment

Update - I found my workaround, using an escape hatch to get the "IGW" child resource in the Vpc construct:

    const igw = vpc.node.findChild('IGW') as CfnInternetGateway;
    new CfnRoute(this, 'IGW', {
      routeTableId: subnet.routeTable.routeTableId,
      destinationCidrBlock: '0.0.0.0/0',
      gatewayId: igw.ref,
    });

All 3 comments

Update - I found my workaround, using an escape hatch to get the "IGW" child resource in the Vpc construct:

    const igw = vpc.node.findChild('IGW') as CfnInternetGateway;
    new CfnRoute(this, 'IGW', {
      routeTableId: subnet.routeTable.routeTableId,
      destinationCidrBlock: '0.0.0.0/0',
      gatewayId: igw.ref,
    });

Glad you could figure it out! :) Closing this issue. Feel free to reopen.

Having a stab at this, hope to have a PR out soon.

Was this page helpful?
0 / 5 - 0 ratings