aws-cdk-lib 2.136.1__py3-none-any.whl → 2.137.0__py3-none-any.whl

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-lib might be problematic. Click here for more details.

@@ -196,6 +196,12 @@ The construct will automatically selects the latest version of Amazon Linux 2023
196
196
  If you prefer to use a custom AMI, use `machineImage: MachineImage.genericLinux({ ... })` and configure the right AMI ID for the
197
197
  regions you want to deploy to.
198
198
 
199
+ > **Warning**
200
+ > The NAT instances created using this method will be **unmonitored**.
201
+ > They are not part of an Auto Scaling Group,
202
+ > and if they become unavailable or are terminated for any reason,
203
+ > will not be restarted or replaced.
204
+
199
205
  By default, the NAT instances will route all traffic. To control what traffic
200
206
  gets routed, pass a custom value for `defaultAllowedTraffic` and access the
201
207
  `NatInstanceProvider.connections` member after having passed the NAT provider to
@@ -215,6 +221,31 @@ ec2.Vpc(self, "TheVPC",
215
221
  provider.connections.allow_from(ec2.Peer.ipv4("1.2.3.4/8"), ec2.Port.tcp(80))
216
222
  ```
217
223
 
224
+ You can also customize the characteristics of your NAT instances, as well as their initialization scripts:
225
+
226
+ ```python
227
+ # bucket: s3.Bucket
228
+
229
+
230
+ user_data = ec2.UserData.for_linux()
231
+ user_data.add_commands(
232
+ (SpreadElement ...ec2.NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS
233
+ ec2.NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS), "echo \"hello world!\" > hello.txt", f"aws s3 cp hello.txt s3://{bucket.bucketName}")
234
+
235
+ provider = ec2.NatProvider.instance_v2(
236
+ instance_type=ec2.InstanceType("t3.small"),
237
+ credit_specification=ec2.CpuCredits.UNLIMITED
238
+ )
239
+
240
+ ec2.Vpc(self, "TheVPC",
241
+ nat_gateway_provider=provider,
242
+ nat_gateways=2
243
+ )
244
+
245
+ for gateway in provider.gateway_instances:
246
+ bucket.grant_write(gateway)
247
+ ```
248
+
218
249
  ```python
219
250
  # Configure the `natGatewayProvider` when defining a Vpc
220
251
  nat_gateway_provider = ec2.NatProvider.instance(
@@ -229,7 +260,7 @@ vpc = ec2.Vpc(self, "MyVpc",
229
260
  )
230
261
  ```
231
262
 
232
- The construct will use the AWS official NAT instance AMI, which has already
263
+ The V1 `NatProvider.instance` construct will use the AWS official NAT instance AMI, which has already
233
264
  reached EOL on Dec 31, 2023. For more information, see the following blog post:
234
265
  [Amazon Linux AMI end of life](https://aws.amazon.com/blogs/aws/update-on-amazon-linux-ami-end-of-life/).
235
266
 
@@ -73441,7 +73472,8 @@ class InstanceType(
73441
73472
  subnet_type=ec2.SubnetType.PUBLIC
73442
73473
  ),
73443
73474
  vpc=vpc,
73444
- removal_policy=RemovalPolicy.SNAPSHOT
73475
+ removal_policy=RemovalPolicy.SNAPSHOT,
73476
+ instance_removal_policy=RemovalPolicy.RETAIN
73445
73477
  )
73446
73478
  '''
73447
73479
 
@@ -78835,6 +78867,7 @@ class NatInstanceImage(
78835
78867
  "key_pair": "keyPair",
78836
78868
  "machine_image": "machineImage",
78837
78869
  "security_group": "securityGroup",
78870
+ "user_data": "userData",
78838
78871
  },
78839
78872
  )
78840
78873
  class NatInstanceProps:
@@ -78848,6 +78881,7 @@ class NatInstanceProps:
78848
78881
  key_pair: typing.Optional[IKeyPair] = None,
78849
78882
  machine_image: typing.Optional[IMachineImage] = None,
78850
78883
  security_group: typing.Optional[ISecurityGroup] = None,
78884
+ user_data: typing.Optional["UserData"] = None,
78851
78885
  ) -> None:
78852
78886
  '''Properties for a NAT instance.
78853
78887
 
@@ -78858,19 +78892,23 @@ class NatInstanceProps:
78858
78892
  :param key_pair: The SSH keypair to grant access to the instance. Default: - No SSH access will be possible.
78859
78893
  :param machine_image: The machine image (AMI) to use. By default, will do an AMI lookup for the latest NAT instance image. If you have a specific AMI ID you want to use, pass a ``GenericLinuxImage``. For example:: ec2.NatProvider.instance({ instanceType: new ec2.InstanceType('t3.micro'), machineImage: new ec2.GenericLinuxImage({ 'us-east-2': 'ami-0f9c61b5a562a16af' }) }) Default: - Latest NAT instance image
78860
78894
  :param security_group: Security Group for NAT instances. Default: - A new security group will be created
78895
+ :param user_data: Custom user data to run on the NAT instances. Default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances
78861
78896
 
78862
78897
  :exampleMetadata: infused
78863
78898
 
78864
78899
  Example::
78865
78900
 
78866
- nat_instance_provider = ec2.NatProvider.instance(
78867
- instance_type=ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.LARGE),
78868
- machine_image=ec2.AmazonLinuxImage(),
78869
- credit_specification=ec2.CpuCredits.UNLIMITED
78901
+ # instance_type: ec2.InstanceType
78902
+
78903
+
78904
+ provider = ec2.NatProvider.instance_v2(
78905
+ instance_type=instance_type,
78906
+ default_allowed_traffic=ec2.NatTrafficDirection.OUTBOUND_ONLY
78870
78907
  )
78871
- ec2.Vpc(self, "VPC",
78872
- nat_gateway_provider=nat_instance_provider
78908
+ ec2.Vpc(self, "TheVPC",
78909
+ nat_gateway_provider=provider
78873
78910
  )
78911
+ provider.connections.allow_from(ec2.Peer.ipv4("1.2.3.4/8"), ec2.Port.tcp(80))
78874
78912
  '''
78875
78913
  if __debug__:
78876
78914
  type_hints = typing.get_type_hints(_typecheckingstub__d7c7c717447859e1ccc181bc97f7752cc3f7fa7afaee4c3a4266eeac32c08643)
@@ -78881,6 +78919,7 @@ class NatInstanceProps:
78881
78919
  check_type(argname="argument key_pair", value=key_pair, expected_type=type_hints["key_pair"])
78882
78920
  check_type(argname="argument machine_image", value=machine_image, expected_type=type_hints["machine_image"])
78883
78921
  check_type(argname="argument security_group", value=security_group, expected_type=type_hints["security_group"])
78922
+ check_type(argname="argument user_data", value=user_data, expected_type=type_hints["user_data"])
78884
78923
  self._values: typing.Dict[builtins.str, typing.Any] = {
78885
78924
  "instance_type": instance_type,
78886
78925
  }
@@ -78896,6 +78935,8 @@ class NatInstanceProps:
78896
78935
  self._values["machine_image"] = machine_image
78897
78936
  if security_group is not None:
78898
78937
  self._values["security_group"] = security_group
78938
+ if user_data is not None:
78939
+ self._values["user_data"] = user_data
78899
78940
 
78900
78941
  @builtins.property
78901
78942
  def instance_type(self) -> InstanceType:
@@ -78983,6 +79024,17 @@ class NatInstanceProps:
78983
79024
  result = self._values.get("security_group")
78984
79025
  return typing.cast(typing.Optional[ISecurityGroup], result)
78985
79026
 
79027
+ @builtins.property
79028
+ def user_data(self) -> typing.Optional["UserData"]:
79029
+ '''Custom user data to run on the NAT instances.
79030
+
79031
+ :default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances
79032
+
79033
+ :see: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html#create-nat-ami
79034
+ '''
79035
+ result = self._values.get("user_data")
79036
+ return typing.cast(typing.Optional["UserData"], result)
79037
+
78986
79038
  def __eq__(self, rhs: typing.Any) -> builtins.bool:
78987
79039
  return isinstance(rhs, self.__class__) and rhs._values == self._values
78988
79040
 
@@ -79055,6 +79107,7 @@ class NatProvider(
79055
79107
  key_pair: typing.Optional[IKeyPair] = None,
79056
79108
  machine_image: typing.Optional[IMachineImage] = None,
79057
79109
  security_group: typing.Optional[ISecurityGroup] = None,
79110
+ user_data: typing.Optional["UserData"] = None,
79058
79111
  ) -> "NatInstanceProvider":
79059
79112
  '''(deprecated) Use NAT instances to provide NAT services for your VPC.
79060
79113
 
@@ -79071,6 +79124,7 @@ class NatProvider(
79071
79124
  :param key_pair: The SSH keypair to grant access to the instance. Default: - No SSH access will be possible.
79072
79125
  :param machine_image: The machine image (AMI) to use. By default, will do an AMI lookup for the latest NAT instance image. If you have a specific AMI ID you want to use, pass a ``GenericLinuxImage``. For example:: ec2.NatProvider.instance({ instanceType: new ec2.InstanceType('t3.micro'), machineImage: new ec2.GenericLinuxImage({ 'us-east-2': 'ami-0f9c61b5a562a16af' }) }) Default: - Latest NAT instance image
79073
79126
  :param security_group: Security Group for NAT instances. Default: - A new security group will be created
79127
+ :param user_data: Custom user data to run on the NAT instances. Default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances
79074
79128
 
79075
79129
  :deprecated:
79076
79130
 
@@ -79088,6 +79142,7 @@ class NatProvider(
79088
79142
  key_pair=key_pair,
79089
79143
  machine_image=machine_image,
79090
79144
  security_group=security_group,
79145
+ user_data=user_data,
79091
79146
  )
79092
79147
 
79093
79148
  return typing.cast("NatInstanceProvider", jsii.sinvoke(cls, "instance", [props]))
@@ -79104,6 +79159,7 @@ class NatProvider(
79104
79159
  key_pair: typing.Optional[IKeyPair] = None,
79105
79160
  machine_image: typing.Optional[IMachineImage] = None,
79106
79161
  security_group: typing.Optional[ISecurityGroup] = None,
79162
+ user_data: typing.Optional["UserData"] = None,
79107
79163
  ) -> "NatInstanceProviderV2":
79108
79164
  '''Use NAT instances to provide NAT services for your VPC.
79109
79165
 
@@ -79120,6 +79176,7 @@ class NatProvider(
79120
79176
  :param key_pair: The SSH keypair to grant access to the instance. Default: - No SSH access will be possible.
79121
79177
  :param machine_image: The machine image (AMI) to use. By default, will do an AMI lookup for the latest NAT instance image. If you have a specific AMI ID you want to use, pass a ``GenericLinuxImage``. For example:: ec2.NatProvider.instance({ instanceType: new ec2.InstanceType('t3.micro'), machineImage: new ec2.GenericLinuxImage({ 'us-east-2': 'ami-0f9c61b5a562a16af' }) }) Default: - Latest NAT instance image
79122
79178
  :param security_group: Security Group for NAT instances. Default: - A new security group will be created
79179
+ :param user_data: Custom user data to run on the NAT instances. Default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances
79123
79180
 
79124
79181
  :see: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html
79125
79182
  '''
@@ -79131,6 +79188,7 @@ class NatProvider(
79131
79188
  key_pair=key_pair,
79132
79189
  machine_image=machine_image,
79133
79190
  security_group=security_group,
79191
+ user_data=user_data,
79134
79192
  )
79135
79193
 
79136
79194
  return typing.cast("NatInstanceProviderV2", jsii.sinvoke(cls, "instanceV2", [props]))
@@ -83942,13 +84000,23 @@ class UserData(
83942
84000
 
83943
84001
  Example::
83944
84002
 
83945
- multipart_user_data = ec2.MultipartUserData()
83946
- commands_user_data = ec2.UserData.for_linux()
83947
- multipart_user_data.add_user_data_part(commands_user_data, ec2.MultipartBody.SHELL_SCRIPT, True)
84003
+ # cluster: eks.Cluster
83948
84004
 
83949
- # Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa.
83950
- multipart_user_data.add_commands("touch /root/multi.txt")
83951
- commands_user_data.add_commands("touch /root/userdata.txt")
84005
+ user_data = ec2.UserData.for_linux()
84006
+ user_data.add_commands("set -o xtrace", f"/etc/eks/bootstrap.sh {cluster.clusterName}")
84007
+ lt = ec2.CfnLaunchTemplate(self, "LaunchTemplate",
84008
+ launch_template_data=ec2.CfnLaunchTemplate.LaunchTemplateDataProperty(
84009
+ image_id="some-ami-id", # custom AMI
84010
+ instance_type="t3.small",
84011
+ user_data=Fn.base64(user_data.render())
84012
+ )
84013
+ )
84014
+ cluster.add_nodegroup_capacity("extra-ng",
84015
+ launch_template_spec=eks.LaunchTemplateSpec(
84016
+ id=lt.ref,
84017
+ version=lt.attr_latest_version_number
84018
+ )
84019
+ )
83952
84020
  '''
83953
84021
 
83954
84022
  def __init__(self) -> None:
@@ -91307,6 +91375,7 @@ class NatInstanceProvider(
91307
91375
  key_pair: typing.Optional[IKeyPair] = None,
91308
91376
  machine_image: typing.Optional[IMachineImage] = None,
91309
91377
  security_group: typing.Optional[ISecurityGroup] = None,
91378
+ user_data: typing.Optional[UserData] = None,
91310
91379
  ) -> None:
91311
91380
  '''
91312
91381
  :param instance_type: Instance type of the NAT instance.
@@ -91316,6 +91385,7 @@ class NatInstanceProvider(
91316
91385
  :param key_pair: The SSH keypair to grant access to the instance. Default: - No SSH access will be possible.
91317
91386
  :param machine_image: The machine image (AMI) to use. By default, will do an AMI lookup for the latest NAT instance image. If you have a specific AMI ID you want to use, pass a ``GenericLinuxImage``. For example:: ec2.NatProvider.instance({ instanceType: new ec2.InstanceType('t3.micro'), machineImage: new ec2.GenericLinuxImage({ 'us-east-2': 'ami-0f9c61b5a562a16af' }) }) Default: - Latest NAT instance image
91318
91387
  :param security_group: Security Group for NAT instances. Default: - A new security group will be created
91388
+ :param user_data: Custom user data to run on the NAT instances. Default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances
91319
91389
 
91320
91390
  :stability: deprecated
91321
91391
  '''
@@ -91327,6 +91397,7 @@ class NatInstanceProvider(
91327
91397
  key_pair=key_pair,
91328
91398
  machine_image=machine_image,
91329
91399
  security_group=security_group,
91400
+ user_data=user_data,
91330
91401
  )
91331
91402
 
91332
91403
  jsii.create(self.__class__, self, [props])
@@ -91435,6 +91506,7 @@ class NatInstanceProviderV2(
91435
91506
  key_pair: typing.Optional[IKeyPair] = None,
91436
91507
  machine_image: typing.Optional[IMachineImage] = None,
91437
91508
  security_group: typing.Optional[ISecurityGroup] = None,
91509
+ user_data: typing.Optional[UserData] = None,
91438
91510
  ) -> None:
91439
91511
  '''
91440
91512
  :param instance_type: Instance type of the NAT instance.
@@ -91444,6 +91516,7 @@ class NatInstanceProviderV2(
91444
91516
  :param key_pair: The SSH keypair to grant access to the instance. Default: - No SSH access will be possible.
91445
91517
  :param machine_image: The machine image (AMI) to use. By default, will do an AMI lookup for the latest NAT instance image. If you have a specific AMI ID you want to use, pass a ``GenericLinuxImage``. For example:: ec2.NatProvider.instance({ instanceType: new ec2.InstanceType('t3.micro'), machineImage: new ec2.GenericLinuxImage({ 'us-east-2': 'ami-0f9c61b5a562a16af' }) }) Default: - Latest NAT instance image
91446
91518
  :param security_group: Security Group for NAT instances. Default: - A new security group will be created
91519
+ :param user_data: Custom user data to run on the NAT instances. Default: UserData.forLinux().addCommands(...NatInstanceProviderV2.DEFAULT_USER_DATA_COMMANDS); - Appropriate user data commands to initialize and configure the NAT instances
91447
91520
  '''
91448
91521
  props = NatInstanceProps(
91449
91522
  instance_type=instance_type,
@@ -91453,6 +91526,7 @@ class NatInstanceProviderV2(
91453
91526
  key_pair=key_pair,
91454
91527
  machine_image=machine_image,
91455
91528
  security_group=security_group,
91529
+ user_data=user_data,
91456
91530
  )
91457
91531
 
91458
91532
  jsii.create(self.__class__, self, [props])
@@ -91492,6 +91566,15 @@ class NatInstanceProviderV2(
91492
91566
  check_type(argname="argument subnet", value=subnet, expected_type=type_hints["subnet"])
91493
91567
  return typing.cast(None, jsii.invoke(self, "configureSubnet", [subnet]))
91494
91568
 
91569
+ @jsii.python.classproperty
91570
+ @jsii.member(jsii_name="DEFAULT_USER_DATA_COMMANDS")
91571
+ def DEFAULT_USER_DATA_COMMANDS(cls) -> typing.List[builtins.str]:
91572
+ '''Amazon Linux 2023 NAT instance user data commands Enable iptables on the instance, enable persistent IP forwarding, configure NAT on instance.
91573
+
91574
+ :see: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html#create-nat-ami
91575
+ '''
91576
+ return typing.cast(typing.List[builtins.str], jsii.sget(cls, "DEFAULT_USER_DATA_COMMANDS"))
91577
+
91495
91578
  @builtins.property
91496
91579
  @jsii.member(jsii_name="configuredGateways")
91497
91580
  def configured_gateways(self) -> typing.List[GatewayConfig]:
@@ -91504,6 +91587,12 @@ class NatInstanceProviderV2(
91504
91587
  '''Manage the Security Groups associated with the NAT instances.'''
91505
91588
  return typing.cast(Connections, jsii.get(self, "connections"))
91506
91589
 
91590
+ @builtins.property
91591
+ @jsii.member(jsii_name="gatewayInstances")
91592
+ def gateway_instances(self) -> typing.List[Instance]:
91593
+ '''Array of gateway instances spawned by the provider after internal configuration.'''
91594
+ return typing.cast(typing.List[Instance], jsii.get(self, "gatewayInstances"))
91595
+
91507
91596
  @builtins.property
91508
91597
  @jsii.member(jsii_name="securityGroup")
91509
91598
  def security_group(self) -> ISecurityGroup:
@@ -104109,6 +104198,7 @@ def _typecheckingstub__d7c7c717447859e1ccc181bc97f7752cc3f7fa7afaee4c3a4266eeac3
104109
104198
  key_pair: typing.Optional[IKeyPair] = None,
104110
104199
  machine_image: typing.Optional[IMachineImage] = None,
104111
104200
  security_group: typing.Optional[ISecurityGroup] = None,
104201
+ user_data: typing.Optional[UserData] = None,
104112
104202
  ) -> None:
104113
104203
  """Type checking stubs"""
104114
104204
  pass
@@ -214,10 +214,9 @@ method. This will modify the IAM policy of the principal to allow it to
214
214
  pull images from this repository.
215
215
 
216
216
  If the pulling principal is not in the same account or is an AWS service that
217
- doesn't assume a role in your account (e.g. AWS CodeBuild), pull permissions
218
- must be granted on the **resource policy** (and not on the principal's policy).
219
- To do that, you can use `asset.repository.addToResourcePolicy(statement)` to
220
- grant the desired principal the following permissions: "ecr:GetDownloadUrlForLayer",
217
+ doesn't assume a role in your account (e.g. AWS CodeBuild), you must either copy the image to a new repository, or
218
+ grant pull permissions on the resource policy of the repository. Since the repository is managed by the CDK bootstrap stack,
219
+ the following permissions must be granted there, or granted manually on the repository: "ecr:GetDownloadUrlForLayer",
221
220
  "ecr:BatchGetImage" and "ecr:BatchCheckLayerAvailability".
222
221
  '''
223
222
  from pkgutil import extend_path