Skip to content

Commit e3351a4

Browse files
authoredAug 23, 2024··
chore(vpcv2): adding rosetta for ReadMe (#31191)
### Issue # (if applicable) Closes #. ### Reason for this change Adding rosetta lib to populate documentation for VPCv2. ### Description of changes Adding rosetta lib to populate documentation for VPCv2. ### Description of how you validated changes Validated that readMe has no failures with below command `yarn rosetta:extract` ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c629172 commit e3351a4

File tree

2 files changed

+80
-61
lines changed

2 files changed

+80
-61
lines changed
 

‎packages/@aws-cdk/aws-ec2-alpha/README.md

+65-61
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ on the VPC being created. `VpcV2` implements the existing [`IVpc`](https://docs.
2121
To create a VPC with both IPv4 and IPv6 support:
2222

2323
```ts
24-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
2524

26-
const stack = new cdk.Stack(app, 'aws-cdk-vpcv2');
27-
new vpc_v2.VpcV2(stack, 'Vpc', {
25+
const stack = new Stack();
26+
new vpc_v2.VpcV2(this, 'Vpc', {
2827
primaryAddressBlock: vpc_v2.IpAddresses.ipv4('10.0.0.0/24'),
2928
secondaryAddressBlocks: [
3029
vpc_v2.IpAddresses.amazonProvidedIpv6({cidrBlockName: 'AmazonProvidedIpv6'}),
@@ -42,22 +41,19 @@ Importing existing VPC in an account into CDK as a `VpcV2` is not yet supported.
4241
This new construct can be used to add subnets to a `VpcV2` instance:
4342

4443
```ts
45-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
46-
import * as ec2 from 'aws-cdk-lib/aws-ec2';
4744

48-
const stack = new cdk.Stack(app, 'aws-cdk-vpcv2');
49-
const vpc = new vpc_v2.VpcV2(stack, 'Vpc', {
45+
const stack = new Stack();
46+
const myVpc = new vpc_v2.VpcV2(this, 'Vpc', {
5047
secondaryAddressBlocks: [
5148
vpc_v2.IpAddresses.amazonProvidedIpv6({ cidrBlockName: 'AmazonProvidedIp'}),
5249
],
5350
});
54-
const vpcFirstIpV6Cidr = Fn.select(0, vpc.ipv6CidrBlocks);
55-
const subCidrs = Fn.cidr(vpcFirstIpV6Cidr, 3, 32);
56-
new vpc_v2.SubnetV2(stack, 'subnetA', {
57-
vpc,
51+
52+
new vpc_v2.SubnetV2(this, 'subnetA', {
53+
vpc: myVpc,
5854
availabilityZone: 'us-east-1a',
59-
cidrBlock: new vpc_v2.IpCidr('10.0.0.0/24'),
60-
ipv6CidrBlock: new vpc_v2.IpCidr(Fn.select(0, subCidrs)),
55+
ipv4CidrBlock: new vpc_v2.IpCidr('10.0.0.0/24'),
56+
ipv6CidrBlock: new vpc_v2.IpCidr('2a05:d02c:25:4000::/60'),
6157
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
6258
})
6359
```
@@ -71,15 +67,14 @@ Additional CIDRs can be adding to the VPC via the `secondaryAddressBlocks` prop.
7167
The following example illustrates the different options of defining the address blocks:
7268

7369
```ts
74-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
7570

76-
const stack = new cdk.Stack(app, 'aws-cdk-vpcv2');
77-
const ipam = new Ipam(stack, 'Ipam', {
71+
const stack = new Stack();
72+
const ipam = new Ipam(this, 'Ipam', {
7873
operatingRegion: ['us-west-1']
7974
});
8075
const ipamPublicPool = ipam.publicScope.addPool('PublicPoolA', {
8176
addressFamily: vpc_v2.AddressFamily.IP_V6,
82-
awsService: 'ec2',
77+
awsService: AwsServiceName.EC2,
8378
locale: 'us-west-1',
8479
publicIpSource: vpc_v2.IpamPoolPublicIpSource.AMAZON,
8580
});
@@ -90,18 +85,18 @@ const ipamPrivatePool = ipam.privateScope.addPool('PrivatePoolA', {
9085
});
9186
ipamPrivatePool.provisionCidr('PrivatePoolACidrA', { netmaskLength: 8 } );
9287

93-
new vpc_v2.VpcV2(stack, 'Vpc', {
88+
new vpc_v2.VpcV2(this, 'Vpc', {
9489
primaryAddressBlock: vpc_v2.IpAddresses.ipv4('10.0.0.0/24'),
9590
secondaryAddressBlocks: [
9691
vpc_v2.IpAddresses.amazonProvidedIpv6({ cidrBlockName: 'AmazonIpv6' }),
9792
vpc_v2.IpAddresses.ipv6Ipam({
98-
ipv6IpamPool: ipamPublicPool,
99-
ipv6NetmaskLength: 52,
93+
ipamPool: ipamPublicPool,
94+
netmaskLength: 52,
10095
cidrBlockName: 'ipv6Ipam',
10196
}),
10297
vpc_v2.IpAddresses.ipv4Ipam({
103-
ipv6IpamPool: ipamPrivatePool,
104-
ipv6NetmaskLength: 8,
98+
ipamPool: ipamPrivatePool,
99+
netmaskLength: 8,
105100
cidrBlockName: 'ipv4Ipam',
106101
}),
107102
],
@@ -116,84 +111,93 @@ Since `VpcV2` does not create subnets automatically, users have full control ove
116111
`RouteTable` is a new construct that allows for route tables to be customized in a variety of ways. For instance, the following example shows how a custom route table can be created and appended to a subnet:
117112

118113
```ts
119-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
120114

121-
const myVpc = new vpc_v2.VpcV2(stack, 'Vpc', {...});
122-
const routeTable = new vpc_v2.RouteTable(stack, 'RouteTable', {
115+
const myVpc = new vpc_v2.VpcV2(this, 'Vpc');
116+
const routeTable = new vpc_v2.RouteTable(this, 'RouteTable', {
123117
vpc: myVpc,
124118
});
125-
const subnet = new vpc_v2.SubnetV2(stack, 'Subnet', {
126-
vpc,
119+
const subnet = new vpc_v2.SubnetV2(this, 'Subnet', {
120+
vpc: myVpc,
127121
routeTable,
128-
...,
122+
availabilityZone: 'eu-west-2a',
123+
ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
124+
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
129125
});
130126
```
131127

132128
`Route`s can be created to link subnets to various different AWS services via gateways and endpoints. Each unique route target has its own dedicated construct that can be routed to a given subnet via the `Route` construct. An example using the `InternetGateway` construct can be seen below:
133129

134130
```ts
135-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
136-
137-
const myVpc = new vpc_v2.VpcV2(stack, 'Vpc', {...});
138-
const routeTable = new vpc_v2.RouteTable(stack, 'RouteTable', {
139-
vpc: vpc.myVpc,
131+
const stack = new Stack();
132+
const myVpc = new vpc_v2.VpcV2(this, 'Vpc');
133+
const routeTable = new vpc_v2.RouteTable(this, 'RouteTable', {
134+
vpc: myVpc,
140135
});
141-
const subnet = new vpc_v2.SubnetV2(stack, 'Subnet', {...});
136+
const subnet = new vpc_v2.SubnetV2(this, 'Subnet', {
137+
vpc: myVpc,
138+
availabilityZone: 'eu-west-2a',
139+
ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
140+
subnetType: ec2.SubnetType.PRIVATE_ISOLATED });
142141

143-
const igw = new vpc_v2.InternetGateway(stack, 'IGW', {
144-
vpcId: vpc.myVpc,
142+
const igw = new vpc_v2.InternetGateway(this, 'IGW', {
143+
vpc: myVpc,
145144
});
146-
new vpc_v2.Route(stack, 'IgwRoute', {
145+
new vpc_v2.Route(this, 'IgwRoute', {
147146
routeTable,
148-
destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
149-
target: igw,
147+
destination: '0.0.0.0/0',
148+
target: { gateway: igw },
150149
});
151150
```
152151

153152
Other route targets may require a deeper set of parameters to set up properly. For instance, the example below illustrates how to set up a `NatGateway`:
154153

155154
```ts
156-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
157155

158-
const myVpc = new vpc_v2.VpcV2(stack, 'Vpc', {...});
159-
const routeTable = new vpc_v2.RouteTable(stack, 'RouteTable', {
160-
vpcId: vpc.myVpc,
156+
const myVpc = new vpc_v2.VpcV2(this, 'Vpc');
157+
const routeTable = new vpc_v2.RouteTable(this, 'RouteTable', {
158+
vpc: myVpc,
161159
});
162-
const subnet = new vpc_v2.SubnetV2(stack, 'Subnet', {...});
160+
const subnet = new vpc_v2.SubnetV2(this, 'Subnet', {
161+
vpc: myVpc,
162+
availabilityZone: 'eu-west-2a',
163+
ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
164+
subnetType: ec2.SubnetType.PRIVATE_ISOLATED });
163165

164-
const natgw = new vpc_v2.NatGateway(stack, 'NatGW', {
166+
const natgw = new vpc_v2.NatGateway(this, 'NatGW', {
165167
subnet: subnet,
166-
vpcId: vpc.myVpc,
167-
connectivityType: 'private',
168+
vpc: myVpc,
169+
connectivityType: NatConnectivityType.PRIVATE,
168170
privateIpAddress: '10.0.0.42',
169171
});
170-
new vpc_v2.Route(stack, 'NatGwRoute', {
172+
new vpc_v2.Route(this, 'NatGwRoute', {
171173
routeTable,
172-
destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
173-
target: natgw,
174+
destination: '0.0.0.0/0',
175+
target: { gateway: natgw },
174176
});
175177
```
176178

177179
It is also possible to set up endpoints connecting other AWS services. For instance, the example below illustrates the linking of a Dynamo DB endpoint via the existing `ec2.GatewayVpcEndpoint` construct as a route target:
178180

179181
```ts
180-
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
181-
import * as ec2 from 'aws-cdk-lib/aws-ec2';
182182

183-
const myVpc = new vpc_v2.VpcV2(stack, 'Vpc', {...});
184-
const routeTable = new vpc_v2.RouteTable(stack, 'RouteTable', {
185-
vpcId: vpc.myVpc,
183+
const myVpc = new vpc_v2.VpcV2(this, 'Vpc');
184+
const routeTable = new vpc_v2.RouteTable(this, 'RouteTable', {
185+
vpc: myVpc,
186186
});
187-
const subnet = new vpc_v2.SubnetV2(stack, 'Subnet', {...});
187+
const subnet = new vpc_v2.SubnetV2(this, 'Subnet', {
188+
vpc: myVpc,
189+
availabilityZone: 'eu-west-2a',
190+
ipv4CidrBlock: new IpCidr('10.0.0.0/24'),
191+
subnetType: ec2.SubnetType.PRIVATE });
188192

189-
const dynamoEndpoint = new GatewayVpcEndpoint(stack, 'DynamoEndpoint', {
193+
const dynamoEndpoint = new ec2.GatewayVpcEndpoint(this, 'DynamoEndpoint', {
190194
service: ec2.GatewayVpcEndpointAwsService.DYNAMODB,
191-
vpc: vpc,
195+
vpc: myVpc,
192196
subnets: [subnet],
193197
});
194-
new vpc_v2.Route(stack, 'DynamoDBRoute', {
198+
new vpc_v2.Route(this, 'DynamoDBRoute', {
195199
routeTable,
196-
destination: vpc_v2.IpAddresses.ipv4('0.0.0.0/0'),
197-
target: dynamoEndpoint,
200+
destination: '0.0.0.0/0',
201+
target: { endpoint: dynamoEndpoint },
198202
});
199203
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Fixture with packages imported, but nothing else
2+
import { Construct } from 'constructs';
3+
import { Stack, App, Fn } from 'aws-cdk-lib';
4+
import * as vpc_v2 from '@aws-cdk/aws-ec2-alpha';
5+
import { Ipam, AwsServiceName, IpCidr } from '@aws-cdk/aws-ec2-alpha';
6+
import { NatConnectivityType } from '@aws-cdk/aws-ec2-alpha'
7+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
8+
9+
class Fixture extends Stack {
10+
constructor(scope: Construct, id: string) {
11+
super(scope, id);
12+
13+
/// here
14+
}
15+
}

0 commit comments

Comments
 (0)
Please sign in to comment.