aws-cdk.aws-ec2-alpha 2.157.0a0__tar.gz → 2.159.0a0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aws-cdk.aws-ec2-alpha might be problematic. Click here for more details.
- aws_cdk_aws_ec2_alpha-2.159.0a0/PKG-INFO +391 -0
- aws_cdk_aws_ec2_alpha-2.159.0a0/README.md +360 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/setup.py +5 -5
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/src/aws_cdk/aws_ec2_alpha/__init__.py +1678 -541
- aws_cdk_aws_ec2_alpha-2.159.0a0/src/aws_cdk/aws_ec2_alpha/_jsii/__init__.py +45 -0
- aws_cdk_aws_ec2_alpha-2.159.0a0/src/aws_cdk/aws_ec2_alpha/_jsii/aws-ec2-alpha@2.159.0-alpha.0.jsii.tgz +0 -0
- aws_cdk_aws_ec2_alpha-2.159.0a0/src/aws_cdk.aws_ec2_alpha.egg-info/PKG-INFO +391 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/src/aws_cdk.aws_ec2_alpha.egg-info/SOURCES.txt +1 -1
- aws_cdk_aws_ec2_alpha-2.159.0a0/src/aws_cdk.aws_ec2_alpha.egg-info/requires.txt +5 -0
- aws_cdk_aws_ec2_alpha-2.157.0a0/PKG-INFO +0 -232
- aws_cdk_aws_ec2_alpha-2.157.0a0/README.md +0 -201
- aws_cdk_aws_ec2_alpha-2.157.0a0/src/aws_cdk/aws_ec2_alpha/_jsii/__init__.py +0 -30
- aws_cdk_aws_ec2_alpha-2.157.0a0/src/aws_cdk/aws_ec2_alpha/_jsii/aws-ec2-alpha@2.157.0-alpha.0.jsii.tgz +0 -0
- aws_cdk_aws_ec2_alpha-2.157.0a0/src/aws_cdk.aws_ec2_alpha.egg-info/PKG-INFO +0 -232
- aws_cdk_aws_ec2_alpha-2.157.0a0/src/aws_cdk.aws_ec2_alpha.egg-info/requires.txt +0 -5
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/LICENSE +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/MANIFEST.in +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/NOTICE +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/pyproject.toml +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/setup.cfg +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/src/aws_cdk/aws_ec2_alpha/py.typed +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/src/aws_cdk.aws_ec2_alpha.egg-info/dependency_links.txt +0 -0
- {aws_cdk_aws_ec2_alpha-2.157.0a0 → aws_cdk_aws_ec2_alpha-2.159.0a0}/src/aws_cdk.aws_ec2_alpha.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: aws-cdk.aws-ec2-alpha
|
|
3
|
+
Version: 2.159.0a0
|
|
4
|
+
Summary: The CDK construct library for VPC V2
|
|
5
|
+
Home-page: https://github.com/aws/aws-cdk
|
|
6
|
+
Author: Amazon Web Services
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Project-URL: Source, https://github.com/aws/aws-cdk.git
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: JavaScript
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Classifier: Development Status :: 4 - Beta
|
|
19
|
+
Classifier: License :: OSI Approved
|
|
20
|
+
Classifier: Framework :: AWS CDK
|
|
21
|
+
Classifier: Framework :: AWS CDK :: 2
|
|
22
|
+
Requires-Python: ~=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
License-File: NOTICE
|
|
26
|
+
Requires-Dist: aws-cdk-lib<3.0.0,>=2.159.0
|
|
27
|
+
Requires-Dist: constructs<11.0.0,>=10.0.0
|
|
28
|
+
Requires-Dist: jsii<2.0.0,>=1.103.1
|
|
29
|
+
Requires-Dist: publication>=0.0.3
|
|
30
|
+
Requires-Dist: typeguard<5.0.0,>=2.13.3
|
|
31
|
+
|
|
32
|
+
# Amazon VpcV2 Construct Library
|
|
33
|
+
|
|
34
|
+
<!--BEGIN STABILITY BANNER-->---
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
> The APIs of higher level constructs in this module are experimental and under active development.
|
|
40
|
+
> They are subject to non-backward compatible changes or removal in any future version. These are
|
|
41
|
+
> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
|
|
42
|
+
> announced in the release notes. This means that while you may use them, you may need to update
|
|
43
|
+
> your source code when upgrading to a newer version of this package.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
<!--END STABILITY BANNER-->
|
|
47
|
+
|
|
48
|
+
## VpcV2
|
|
49
|
+
|
|
50
|
+
`VpcV2` is a re-write of the [`ec2.Vpc`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Vpc.html) construct. This new construct enables higher level of customization
|
|
51
|
+
on the VPC being created. `VpcV2` implements the existing [`IVpc`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html), therefore,
|
|
52
|
+
`VpcV2` is compatible with other constructs that accepts `IVpc` (e.g. [`ApplicationLoadBalancer`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ApplicationLoadBalancer.html#construct-props)).
|
|
53
|
+
|
|
54
|
+
To create a VPC with both IPv4 and IPv6 support:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
stack = Stack()
|
|
58
|
+
VpcV2(self, "Vpc",
|
|
59
|
+
primary_address_block=IpAddresses.ipv4("10.0.0.0/24"),
|
|
60
|
+
secondary_address_blocks=[
|
|
61
|
+
IpAddresses.amazon_provided_ipv6(cidr_block_name="AmazonProvidedIpv6")
|
|
62
|
+
]
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`VpcV2` does not automatically create subnets or allocate IP addresses, which is different from the `Vpc` construct.
|
|
67
|
+
|
|
68
|
+
Importing existing VPC in an account into CDK as a `VpcV2` is not yet supported.
|
|
69
|
+
|
|
70
|
+
## SubnetV2
|
|
71
|
+
|
|
72
|
+
`SubnetV2` is a re-write of the [`ec2.Subnet`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Subnet.html) construct.
|
|
73
|
+
This new construct can be used to add subnets to a `VpcV2` instance:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
stack = Stack()
|
|
77
|
+
my_vpc = VpcV2(self, "Vpc",
|
|
78
|
+
secondary_address_blocks=[
|
|
79
|
+
IpAddresses.amazon_provided_ipv6(cidr_block_name="AmazonProvidedIp")
|
|
80
|
+
]
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
SubnetV2(self, "subnetA",
|
|
84
|
+
vpc=my_vpc,
|
|
85
|
+
availability_zone="us-east-1a",
|
|
86
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
87
|
+
ipv6_cidr_block=IpCidr("2a05:d02c:25:4000::/60"),
|
|
88
|
+
subnet_type=SubnetType.PRIVATE_ISOLATED
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Same as `VpcV2`, importing existing subnets is not yet supported.
|
|
93
|
+
|
|
94
|
+
## IP Addresses Management
|
|
95
|
+
|
|
96
|
+
By default `VpcV2` uses `10.0.0.0/16` as the primary CIDR if none is defined.
|
|
97
|
+
Additional CIDRs can be adding to the VPC via the `secondaryAddressBlocks` prop.
|
|
98
|
+
The following example illustrates the different options of defining the address blocks:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
stack = Stack()
|
|
102
|
+
ipam = Ipam(self, "Ipam",
|
|
103
|
+
operating_region=["us-west-1"]
|
|
104
|
+
)
|
|
105
|
+
ipam_public_pool = ipam.public_scope.add_pool("PublicPoolA",
|
|
106
|
+
address_family=AddressFamily.IP_V6,
|
|
107
|
+
aws_service=AwsServiceName.EC2,
|
|
108
|
+
locale="us-west-1",
|
|
109
|
+
public_ip_source=IpamPoolPublicIpSource.AMAZON
|
|
110
|
+
)
|
|
111
|
+
ipam_public_pool.provision_cidr("PublicPoolACidrA", netmask_length=52)
|
|
112
|
+
|
|
113
|
+
ipam_private_pool = ipam.private_scope.add_pool("PrivatePoolA",
|
|
114
|
+
address_family=AddressFamily.IP_V4
|
|
115
|
+
)
|
|
116
|
+
ipam_private_pool.provision_cidr("PrivatePoolACidrA", netmask_length=8)
|
|
117
|
+
|
|
118
|
+
VpcV2(self, "Vpc",
|
|
119
|
+
primary_address_block=IpAddresses.ipv4("10.0.0.0/24"),
|
|
120
|
+
secondary_address_blocks=[
|
|
121
|
+
IpAddresses.amazon_provided_ipv6(cidr_block_name="AmazonIpv6"),
|
|
122
|
+
IpAddresses.ipv6_ipam(
|
|
123
|
+
ipam_pool=ipam_public_pool,
|
|
124
|
+
netmask_length=52,
|
|
125
|
+
cidr_block_name="ipv6Ipam"
|
|
126
|
+
),
|
|
127
|
+
IpAddresses.ipv4_ipam(
|
|
128
|
+
ipam_pool=ipam_private_pool,
|
|
129
|
+
netmask_length=8,
|
|
130
|
+
cidr_block_name="ipv4Ipam"
|
|
131
|
+
)
|
|
132
|
+
]
|
|
133
|
+
)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Since `VpcV2` does not create subnets automatically, users have full control over IP addresses allocation across subnets.
|
|
137
|
+
|
|
138
|
+
## Routing
|
|
139
|
+
|
|
140
|
+
`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:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
144
|
+
route_table = RouteTable(self, "RouteTable",
|
|
145
|
+
vpc=my_vpc
|
|
146
|
+
)
|
|
147
|
+
subnet = SubnetV2(self, "Subnet",
|
|
148
|
+
vpc=my_vpc,
|
|
149
|
+
route_table=route_table,
|
|
150
|
+
availability_zone="eu-west-2a",
|
|
151
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
152
|
+
subnet_type=SubnetType.PRIVATE_ISOLATED
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`Routes` 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:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
stack = Stack()
|
|
160
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
161
|
+
route_table = RouteTable(self, "RouteTable",
|
|
162
|
+
vpc=my_vpc
|
|
163
|
+
)
|
|
164
|
+
subnet = SubnetV2(self, "Subnet",
|
|
165
|
+
vpc=my_vpc,
|
|
166
|
+
availability_zone="eu-west-2a",
|
|
167
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
168
|
+
subnet_type=SubnetType.PRIVATE_ISOLATED
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
igw = InternetGateway(self, "IGW",
|
|
172
|
+
vpc=my_vpc
|
|
173
|
+
)
|
|
174
|
+
Route(self, "IgwRoute",
|
|
175
|
+
route_table=route_table,
|
|
176
|
+
destination="0.0.0.0/0",
|
|
177
|
+
target={"gateway": igw}
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Alternatively, `Routes` can also be created via method `addRoute` in the `RouteTable` class. An example using the `EgressOnlyInternetGateway` construct can be seen below:
|
|
182
|
+
Note: `EgressOnlyInternetGateway` can only be used to set up outbound IPv6 routing.
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
stack = Stack()
|
|
186
|
+
my_vpc = VpcV2(self, "Vpc",
|
|
187
|
+
primary_address_block=IpAddresses.ipv4("10.1.0.0/16"),
|
|
188
|
+
secondary_address_blocks=[IpAddresses.amazon_provided_ipv6(
|
|
189
|
+
cidr_block_name="AmazonProvided"
|
|
190
|
+
)]
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
eigw = EgressOnlyInternetGateway(self, "EIGW",
|
|
194
|
+
vpc=my_vpc
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
route_table = RouteTable(self, "RouteTable",
|
|
198
|
+
vpc=my_vpc
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
route_table.add_route("EIGW", "::/0", {"gateway": eigw})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
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`:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
208
|
+
route_table = RouteTable(self, "RouteTable",
|
|
209
|
+
vpc=my_vpc
|
|
210
|
+
)
|
|
211
|
+
subnet = SubnetV2(self, "Subnet",
|
|
212
|
+
vpc=my_vpc,
|
|
213
|
+
availability_zone="eu-west-2a",
|
|
214
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
215
|
+
subnet_type=SubnetType.PRIVATE_ISOLATED
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
natgw = NatGateway(self, "NatGW",
|
|
219
|
+
subnet=subnet,
|
|
220
|
+
vpc=my_vpc,
|
|
221
|
+
connectivity_type=NatConnectivityType.PRIVATE,
|
|
222
|
+
private_ip_address="10.0.0.42"
|
|
223
|
+
)
|
|
224
|
+
Route(self, "NatGwRoute",
|
|
225
|
+
route_table=route_table,
|
|
226
|
+
destination="0.0.0.0/0",
|
|
227
|
+
target={"gateway": natgw}
|
|
228
|
+
)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
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:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
stack = Stack()
|
|
235
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
236
|
+
route_table = RouteTable(self, "RouteTable",
|
|
237
|
+
vpc=my_vpc
|
|
238
|
+
)
|
|
239
|
+
subnet = SubnetV2(self, "Subnet",
|
|
240
|
+
vpc=my_vpc,
|
|
241
|
+
availability_zone="eu-west-2a",
|
|
242
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
243
|
+
subnet_type=SubnetType.PRIVATE
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
dynamo_endpoint = ec2.GatewayVpcEndpoint(self, "DynamoEndpoint",
|
|
247
|
+
service=ec2.GatewayVpcEndpointAwsService.DYNAMODB,
|
|
248
|
+
vpc=my_vpc,
|
|
249
|
+
subnets=[subnet]
|
|
250
|
+
)
|
|
251
|
+
Route(self, "DynamoDBRoute",
|
|
252
|
+
route_table=route_table,
|
|
253
|
+
destination="0.0.0.0/0",
|
|
254
|
+
target={"endpoint": dynamo_endpoint}
|
|
255
|
+
)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Adding Egress-Only Internet Gateway to VPC
|
|
259
|
+
|
|
260
|
+
An egress-only internet gateway is a horizontally scaled, redundant, and highly available VPC component that allows outbound communication over IPv6 from instances in your VPC to the internet, and prevents the internet from initiating an IPv6 connection with your instances.
|
|
261
|
+
|
|
262
|
+
For more information see [Enable outbound IPv6 traffic using an egress-only internet gateway](https://docs.aws.amazon.com/vpc/latest/userguide/egress-only-internet-gateway.html).
|
|
263
|
+
|
|
264
|
+
VpcV2 supports adding an egress only internet gateway to VPC using the `addEgressOnlyInternetGateway` method.
|
|
265
|
+
|
|
266
|
+
By default, this method sets up a route to all outbound IPv6 address ranges, unless a specific destination is provided by the user. It can only be configured for IPv6-enabled VPCs.
|
|
267
|
+
The `Subnets` parameter accepts a `SubnetFilter`, which can be based on a `SubnetType` in VpcV2. A new route will be added to the route tables of all subnets that match this filter.
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
stack = Stack()
|
|
271
|
+
my_vpc = VpcV2(self, "Vpc",
|
|
272
|
+
primary_address_block=IpAddresses.ipv4("10.1.0.0/16"),
|
|
273
|
+
secondary_address_blocks=[IpAddresses.amazon_provided_ipv6(
|
|
274
|
+
cidr_block_name="AmazonProvided"
|
|
275
|
+
)]
|
|
276
|
+
)
|
|
277
|
+
route_table = RouteTable(self, "RouteTable",
|
|
278
|
+
vpc=my_vpc
|
|
279
|
+
)
|
|
280
|
+
subnet = SubnetV2(self, "Subnet",
|
|
281
|
+
vpc=my_vpc,
|
|
282
|
+
availability_zone="eu-west-2a",
|
|
283
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
284
|
+
ipv6_cidr_block=IpCidr("2001:db8:1::/64"),
|
|
285
|
+
subnet_type=SubnetType.PRIVATE
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
my_vpc.add_egress_only_internet_gateway(
|
|
289
|
+
subnets=[ec2.SubnetSelection(subnet_type=SubnetType.PRIVATE)],
|
|
290
|
+
destination="::/60"
|
|
291
|
+
)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Adding NATGateway to the VPC
|
|
295
|
+
|
|
296
|
+
A NAT gateway is a Network Address Translation (NAT) service.You can use a NAT gateway so that instances in a private subnet can connect to services outside your VPC but external services cannot initiate a connection with those instances.
|
|
297
|
+
|
|
298
|
+
For more information, see [NAT gateway basics](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html).
|
|
299
|
+
|
|
300
|
+
When you create a NAT gateway, you specify one of the following connectivity types:
|
|
301
|
+
|
|
302
|
+
**Public – (Default)**: Instances in private subnets can connect to the internet through a public NAT gateway, but cannot receive unsolicited inbound connections from the internet
|
|
303
|
+
|
|
304
|
+
**Private**: Instances in private subnets can connect to other VPCs or your on-premises network through a private NAT gateway.
|
|
305
|
+
|
|
306
|
+
To define the NAT gateway connectivity type as `ConnectivityType.Public`, you need to ensure that there is an IGW(Internet Gateway) attached to the subnet's VPC.
|
|
307
|
+
Since a NATGW is associated with a particular subnet, providing `subnet` field in the input props is mandatory.
|
|
308
|
+
|
|
309
|
+
Additionally, you can set up a route in any route table with the target set to the NAT Gateway. The function `addNatGateway` returns a `NATGateway` object that you can reference later.
|
|
310
|
+
|
|
311
|
+
The code example below provides the definition for adding a NAT gateway to your subnet:
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
stack = Stack()
|
|
315
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
316
|
+
route_table = RouteTable(self, "RouteTable",
|
|
317
|
+
vpc=my_vpc
|
|
318
|
+
)
|
|
319
|
+
subnet = SubnetV2(self, "Subnet",
|
|
320
|
+
vpc=my_vpc,
|
|
321
|
+
availability_zone="eu-west-2a",
|
|
322
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
323
|
+
subnet_type=SubnetType.PUBLIC
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
my_vpc.add_internet_gateway()
|
|
327
|
+
my_vpc.add_nat_gateway(
|
|
328
|
+
subnet=subnet,
|
|
329
|
+
connectivity_type=NatConnectivityType.PUBLIC
|
|
330
|
+
)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Enable VPNGateway for the VPC
|
|
334
|
+
|
|
335
|
+
A virtual private gateway is the endpoint on the VPC side of your VPN connection.
|
|
336
|
+
|
|
337
|
+
For more information, see [What is AWS Site-to-Site VPN?](https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html).
|
|
338
|
+
|
|
339
|
+
VPN route propagation is a feature in Amazon Web Services (AWS) that automatically updates route tables in your Virtual Private Cloud (VPC) with routes learned from a VPN connection.
|
|
340
|
+
|
|
341
|
+
To enable VPN route propogation, use the `vpnRoutePropagation` property to specify the subnets as an input to the function. VPN route propagation will then be enabled for each subnet with the corresponding route table IDs.
|
|
342
|
+
|
|
343
|
+
Additionally, you can set up a route in any route table with the target set to the VPN Gateway. The function `enableVpnGatewayV2` returns a `VPNGatewayV2` object that you can reference later.
|
|
344
|
+
|
|
345
|
+
The code example below provides the definition for setting up a VPN gateway with `vpnRoutePropogation` enabled:
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
stack = Stack()
|
|
349
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
350
|
+
vpn_gateway = my_vpc.enable_vpn_gateway_v2(
|
|
351
|
+
vpn_route_propagation=[ec2.SubnetSelection(subnet_type=SubnetType.PUBLIC)],
|
|
352
|
+
type=VpnConnectionType.IPSEC_1
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
route_table = RouteTable(stack, "routeTable",
|
|
356
|
+
vpc=my_vpc
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
Route(stack, "route",
|
|
360
|
+
destination="172.31.0.0/24",
|
|
361
|
+
target={"gateway": vpn_gateway},
|
|
362
|
+
route_table=route_table
|
|
363
|
+
)
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## Adding InternetGateway to the VPC
|
|
367
|
+
|
|
368
|
+
An internet gateway is a horizontally scaled, redundant, and highly available VPC component that allows communication between your VPC and the internet. It supports both IPv4 and IPv6 traffic.
|
|
369
|
+
|
|
370
|
+
For more information, see [Enable VPC internet access using internet gateways](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-igw-internet-access.html).
|
|
371
|
+
|
|
372
|
+
You can add an internet gateway to a VPC using `addInternetGateway` method. By default, this method creates a route in all Public Subnets with outbound destination set to `0.0.0.0` for IPv4 and `::0` for IPv6 enabled VPC.
|
|
373
|
+
Instead of using the default settings, you can configure a custom destinatation range by providing an optional input `destination` to the method.
|
|
374
|
+
|
|
375
|
+
The code example below shows how to add an internet gateway with a custom outbound destination IP range:
|
|
376
|
+
|
|
377
|
+
```python
|
|
378
|
+
stack = Stack()
|
|
379
|
+
my_vpc = VpcV2(self, "Vpc")
|
|
380
|
+
|
|
381
|
+
subnet = SubnetV2(self, "Subnet",
|
|
382
|
+
vpc=my_vpc,
|
|
383
|
+
availability_zone="eu-west-2a",
|
|
384
|
+
ipv4_cidr_block=IpCidr("10.0.0.0/24"),
|
|
385
|
+
subnet_type=SubnetType.PUBLIC
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
my_vpc.add_internet_gateway(
|
|
389
|
+
ipv4_destination="192.168.0.0/16"
|
|
390
|
+
)
|
|
391
|
+
```
|