-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ec2): access a vpc's internet gateway (#7939)
This commit introduces a new `internetGateway` attribute to the VPC construct to allow for creative routing using the default IGW added with when using a public subnet. Resolves #5327 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
5 changed files
with
301 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
packages/@aws-cdk/aws-ec2/test/integ.vpc-gateway.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
{ | ||
"Resources": { | ||
"MyVpcF9F0CA6F": { | ||
"Type": "AWS::EC2::VPC", | ||
"Properties": { | ||
"CidrBlock": "10.0.0.0/16", | ||
"EnableDnsHostnames": true, | ||
"EnableDnsSupport": true, | ||
"InstanceTenancy": "default", | ||
"Tags": [ | ||
{ | ||
"Key": "Name", | ||
"Value": "aws-cdk-ec2-vpc-gateway/MyVpc" | ||
} | ||
] | ||
} | ||
}, | ||
"MyVpcPublicSubnet1SubnetF6608456": { | ||
"Type": "AWS::EC2::Subnet", | ||
"Properties": { | ||
"CidrBlock": "10.0.0.0/17", | ||
"VpcId": { | ||
"Ref": "MyVpcF9F0CA6F" | ||
}, | ||
"AvailabilityZone": "test-region-1a", | ||
"MapPublicIpOnLaunch": true, | ||
"Tags": [ | ||
{ | ||
"Key": "aws-cdk:subnet-name", | ||
"Value": "Public" | ||
}, | ||
{ | ||
"Key": "aws-cdk:subnet-type", | ||
"Value": "Public" | ||
}, | ||
{ | ||
"Key": "Name", | ||
"Value": "aws-cdk-ec2-vpc-gateway/MyVpc/PublicSubnet1" | ||
} | ||
] | ||
} | ||
}, | ||
"MyVpcPublicSubnet1RouteTableC46AB2F4": { | ||
"Type": "AWS::EC2::RouteTable", | ||
"Properties": { | ||
"VpcId": { | ||
"Ref": "MyVpcF9F0CA6F" | ||
}, | ||
"Tags": [ | ||
{ | ||
"Key": "Name", | ||
"Value": "aws-cdk-ec2-vpc-gateway/MyVpc/PublicSubnet1" | ||
} | ||
] | ||
} | ||
}, | ||
"MyVpcPublicSubnet1RouteTableAssociation2ECEE1CB": { | ||
"Type": "AWS::EC2::SubnetRouteTableAssociation", | ||
"Properties": { | ||
"RouteTableId": { | ||
"Ref": "MyVpcPublicSubnet1RouteTableC46AB2F4" | ||
}, | ||
"SubnetId": { | ||
"Ref": "MyVpcPublicSubnet1SubnetF6608456" | ||
} | ||
} | ||
}, | ||
"MyVpcPublicSubnet1DefaultRoute95FDF9EB": { | ||
"Type": "AWS::EC2::Route", | ||
"Properties": { | ||
"RouteTableId": { | ||
"Ref": "MyVpcPublicSubnet1RouteTableC46AB2F4" | ||
}, | ||
"DestinationCidrBlock": "0.0.0.0/0", | ||
"GatewayId": { | ||
"Ref": "MyVpcIGW5C4A4F63" | ||
} | ||
}, | ||
"DependsOn": [ | ||
"MyVpcVPCGW488ACE0D" | ||
] | ||
}, | ||
"MyVpcIsolatedSubnet1Subnet2259FE9F": { | ||
"Type": "AWS::EC2::Subnet", | ||
"Properties": { | ||
"CidrBlock": "10.0.128.0/17", | ||
"VpcId": { | ||
"Ref": "MyVpcF9F0CA6F" | ||
}, | ||
"AvailabilityZone": "test-region-1a", | ||
"MapPublicIpOnLaunch": false, | ||
"Tags": [ | ||
{ | ||
"Key": "aws-cdk:subnet-name", | ||
"Value": "Isolated" | ||
}, | ||
{ | ||
"Key": "aws-cdk:subnet-type", | ||
"Value": "Isolated" | ||
}, | ||
{ | ||
"Key": "Name", | ||
"Value": "aws-cdk-ec2-vpc-gateway/MyVpc/IsolatedSubnet1" | ||
} | ||
] | ||
} | ||
}, | ||
"MyVpcIsolatedSubnet1RouteTable67AEA7B8": { | ||
"Type": "AWS::EC2::RouteTable", | ||
"Properties": { | ||
"VpcId": { | ||
"Ref": "MyVpcF9F0CA6F" | ||
}, | ||
"Tags": [ | ||
{ | ||
"Key": "Name", | ||
"Value": "aws-cdk-ec2-vpc-gateway/MyVpc/IsolatedSubnet1" | ||
} | ||
] | ||
} | ||
}, | ||
"MyVpcIsolatedSubnet1RouteTableAssociationCDAE5449": { | ||
"Type": "AWS::EC2::SubnetRouteTableAssociation", | ||
"Properties": { | ||
"RouteTableId": { | ||
"Ref": "MyVpcIsolatedSubnet1RouteTable67AEA7B8" | ||
}, | ||
"SubnetId": { | ||
"Ref": "MyVpcIsolatedSubnet1Subnet2259FE9F" | ||
} | ||
} | ||
}, | ||
"MyVpcIsolatedSubnet1MyRouteCDD7D172": { | ||
"Type": "AWS::EC2::Route", | ||
"Properties": { | ||
"RouteTableId": { | ||
"Ref": "MyVpcIsolatedSubnet1RouteTable67AEA7B8" | ||
}, | ||
"DestinationCidrBlock": "8.8.8.8/32", | ||
"GatewayId": { | ||
"Ref": "MyVpcIGW5C4A4F63" | ||
} | ||
} | ||
}, | ||
"MyVpcIGW5C4A4F63": { | ||
"Type": "AWS::EC2::InternetGateway", | ||
"Properties": { | ||
"Tags": [ | ||
{ | ||
"Key": "Name", | ||
"Value": "aws-cdk-ec2-vpc-gateway/MyVpc" | ||
} | ||
] | ||
} | ||
}, | ||
"MyVpcVPCGW488ACE0D": { | ||
"Type": "AWS::EC2::VPCGatewayAttachment", | ||
"Properties": { | ||
"VpcId": { | ||
"Ref": "MyVpcF9F0CA6F" | ||
}, | ||
"InternetGatewayId": { | ||
"Ref": "MyVpcIGW5C4A4F63" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as ec2 from '../lib'; | ||
|
||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'aws-cdk-ec2-vpc-gateway'); | ||
|
||
const vpc = new ec2.Vpc(stack, 'MyVpc', { | ||
maxAzs: 1, | ||
subnetConfiguration: [ | ||
{ | ||
subnetType: ec2.SubnetType.PUBLIC, | ||
name: 'Public', | ||
}, | ||
{ | ||
subnetType: ec2.SubnetType.ISOLATED, | ||
name: 'Isolated', | ||
}, | ||
], | ||
}); | ||
|
||
(vpc.isolatedSubnets[0] as ec2.Subnet).addRoute('MyRoute', { | ||
routerId: vpc.internetGatewayId!, | ||
routerType: ec2.RouterType.GATEWAY, | ||
destinationCidrBlock: '8.8.8.8/32', | ||
}); | ||
|
||
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters