aws-cdk-lib 2.191.0__py3-none-any.whl → 2.193.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.

@@ -88552,17 +88552,20 @@ class Port(metaclass=jsii.JSIIMeta, jsii_type="aws-cdk-lib.aws_ec2.Port"):
88552
88552
 
88553
88553
  Example::
88554
88554
 
88555
- # instance_type: ec2.InstanceType
88556
-
88555
+ # vpc: ec2.Vpc
88557
88556
 
88558
- provider = ec2.NatProvider.instance_v2(
88559
- instance_type=instance_type,
88560
- default_allowed_traffic=ec2.NatTrafficDirection.OUTBOUND_ONLY
88561
- )
88562
- ec2.Vpc(self, "TheVPC",
88563
- nat_gateway_provider=provider
88557
+ cluster = msk.Cluster(self, "Cluster",
88558
+ cluster_name="myCluster",
88559
+ kafka_version=msk.KafkaVersion.V3_8_X,
88560
+ vpc=vpc
88564
88561
  )
88565
- provider.connections.allow_from(ec2.Peer.ipv4("1.2.3.4/8"), ec2.Port.HTTP)
88562
+
88563
+ cluster.connections.allow_from(
88564
+ ec2.Peer.ipv4("1.2.3.4/8"),
88565
+ ec2.Port.tcp(2181))
88566
+ cluster.connections.allow_from(
88567
+ ec2.Peer.ipv4("1.2.3.4/8"),
88568
+ ec2.Port.tcp(9094))
88566
88569
  '''
88567
88570
 
88568
88571
  def __init__(
@@ -90465,22 +90468,19 @@ class SecurityGroupProps:
90465
90468
 
90466
90469
  Example::
90467
90470
 
90468
- # vpc: ec2.Vpc
90469
-
90470
-
90471
- sg1 = ec2.SecurityGroup(self, "sg1",
90472
- vpc=vpc
90473
- )
90474
- sg2 = ec2.SecurityGroup(self, "sg2",
90475
- vpc=vpc
90476
- )
90471
+ vpc = ec2.Vpc(self, "Vpc", max_azs=1)
90472
+ cluster = ecs.Cluster(self, "EcsCluster", vpc=vpc)
90473
+ security_group = ec2.SecurityGroup(self, "SG", vpc=vpc)
90477
90474
 
90478
- launch_template = ec2.LaunchTemplate(self, "LaunchTemplate",
90479
- machine_image=ec2.MachineImage.latest_amazon_linux2023(),
90480
- security_group=sg1
90475
+ scheduled_fargate_task = ecs_patterns.ScheduledFargateTask(self, "ScheduledFargateTask",
90476
+ cluster=cluster,
90477
+ scheduled_fargate_task_image_options=ecsPatterns.ScheduledFargateTaskImageOptions(
90478
+ image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
90479
+ memory_limit_mi_b=512
90480
+ ),
90481
+ schedule=appscaling.Schedule.expression("rate(1 minute)"),
90482
+ security_groups=[security_group]
90481
90483
  )
90482
-
90483
- launch_template.add_security_group(sg2)
90484
90484
  '''
90485
90485
  if __debug__:
90486
90486
  type_hints = typing.get_type_hints(_typecheckingstub__4e55e0c52b51f92e83b1f8d6b7a5b22268d0369a14dab808b8f2f5f233e5b622)
@@ -95288,25 +95288,25 @@ class VpcProps:
95288
95288
 
95289
95289
  Example::
95290
95290
 
95291
- import aws_cdk.aws_ec2 as ec2
95292
-
95293
-
95294
- vpc = ec2.Vpc(self, "Vpc",
95295
- ip_addresses=ec2.IpAddresses.cidr("10.0.0.0/16")
95291
+ vpc = ec2.Vpc(self, "VPC",
95292
+ cidr="10.0.0.0/16",
95293
+ nat_gateways=0,
95294
+ max_azs=3,
95295
+ subnet_configuration=[ec2.SubnetConfiguration(
95296
+ name="public-subnet-1",
95297
+ subnet_type=ec2.SubnetType.PUBLIC,
95298
+ cidr_mask=24
95299
+ )
95300
+ ]
95296
95301
  )
95297
95302
 
95298
- vpc_connector = apprunner.VpcConnector(self, "VpcConnector",
95303
+ instance = ec2.Instance(self, "Instance",
95299
95304
  vpc=vpc,
95300
- vpc_subnets=vpc.select_subnets(subnet_type=ec2.SubnetType.PUBLIC),
95301
- vpc_connector_name="MyVpcConnector"
95302
- )
95303
-
95304
- apprunner.Service(self, "Service",
95305
- source=apprunner.Source.from_ecr_public(
95306
- image_configuration=apprunner.ImageConfiguration(port=8000),
95307
- image_identifier="public.ecr.aws/aws-containers/hello-app-runner:latest"
95308
- ),
95309
- vpc_connector=vpc_connector
95305
+ vpc_subnets=ec2.SubnetSelection(subnet_group_name="public-subnet-1"),
95306
+ instance_type=ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.NANO),
95307
+ machine_image=ec2.AmazonLinuxImage(generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2),
95308
+ detailed_monitoring=True,
95309
+ associate_public_ip_address=True
95310
95310
  )
95311
95311
  '''
95312
95312
  if isinstance(nat_gateway_subnets, dict):
@@ -19995,28 +19995,43 @@ class ClusterProps:
19995
19995
 
19996
19996
  Example::
19997
19997
 
19998
- vpc = ec2.Vpc.from_lookup(self, "Vpc",
19999
- is_default=True
19998
+ # vpc: ec2.Vpc
19999
+
20000
+
20001
+ cluster = ecs.Cluster(self, "Cluster",
20002
+ vpc=vpc
20000
20003
  )
20001
- cluster = ecs.Cluster(self, "ECSCluster", vpc=vpc)
20002
20004
 
20003
- task_definition = ecs.TaskDefinition(self, "TD",
20004
- compatibility=ecs.Compatibility.FARGATE,
20005
- cpu="256",
20006
- memory_mi_b="512"
20005
+ auto_scaling_group = autoscaling.AutoScalingGroup(self, "ASG",
20006
+ vpc=vpc,
20007
+ instance_type=ec2.InstanceType("t2.micro"),
20008
+ machine_image=ecs.EcsOptimizedImage.amazon_linux2(),
20009
+ min_capacity=0,
20010
+ max_capacity=100
20007
20011
  )
20008
20012
 
20009
- task_definition.add_container("TheContainer",
20010
- image=ecs.ContainerImage.from_registry("foo/bar")
20013
+ capacity_provider = ecs.AsgCapacityProvider(self, "AsgCapacityProvider",
20014
+ auto_scaling_group=auto_scaling_group,
20015
+ instance_warmup_period=300
20011
20016
  )
20017
+ cluster.add_asg_capacity_provider(capacity_provider)
20012
20018
 
20013
- run_task = tasks.EcsRunTask(self, "Run",
20014
- integration_pattern=sfn.IntegrationPattern.RUN_JOB,
20019
+ task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")
20020
+
20021
+ task_definition.add_container("web",
20022
+ image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
20023
+ memory_reservation_mi_b=256
20024
+ )
20025
+
20026
+ ecs.Ec2Service(self, "EC2Service",
20015
20027
  cluster=cluster,
20016
20028
  task_definition=task_definition,
20017
- launch_target=tasks.EcsFargateLaunchTarget(),
20018
- cpu="1024",
20019
- memory_mi_b="1048"
20029
+ min_healthy_percent=100,
20030
+ capacity_provider_strategies=[ecs.CapacityProviderStrategy(
20031
+ capacity_provider=capacity_provider.capacity_provider_name,
20032
+ weight=1
20033
+ )
20034
+ ]
20020
20035
  )
20021
20036
  '''
20022
20037
  if isinstance(capacity, dict):
@@ -21173,26 +21188,34 @@ class ContainerDefinitionOptions:
21173
21188
 
21174
21189
  Example::
21175
21190
 
21191
+ # task_definition: ecs.TaskDefinition
21176
21192
  # cluster: ecs.Cluster
21177
- # vpc: ec2.Vpc
21178
21193
 
21179
- service = ecs_patterns.ApplicationLoadBalancedFargateService(self, "Service",
21194
+
21195
+ # Add a container to the task definition
21196
+ specific_container = task_definition.add_container("Container",
21197
+ image=ecs.ContainerImage.from_registry("/aws/aws-example-app"),
21198
+ memory_limit_mi_b=2048
21199
+ )
21200
+
21201
+ # Add a port mapping
21202
+ specific_container.add_port_mappings(
21203
+ container_port=7600,
21204
+ protocol=ecs.Protocol.TCP
21205
+ )
21206
+
21207
+ ecs.Ec2Service(self, "Service",
21180
21208
  cluster=cluster,
21181
- vpc=vpc,
21182
- desired_count=1,
21209
+ task_definition=task_definition,
21183
21210
  min_healthy_percent=100,
21184
- task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
21185
- image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
21186
- docker_labels={
21187
- "application.label.one": "first_label",
21188
- "application.label.two": "second_label"
21189
- }
21211
+ cloud_map_options=ecs.CloudMapOptions(
21212
+ # Create SRV records - useful for bridge networking
21213
+ dns_record_type=cloudmap.DnsRecordType.SRV,
21214
+ # Targets port TCP port 7600 `specificContainer`
21215
+ container=specific_container,
21216
+ container_port=7600
21190
21217
  )
21191
21218
  )
21192
-
21193
- service.task_definition.add_container("Sidecar",
21194
- image=ecs.ContainerImage.from_registry("example/metrics-sidecar")
21195
- )
21196
21219
  '''
21197
21220
  if isinstance(health_check, dict):
21198
21221
  health_check = HealthCheck(**health_check)
@@ -22674,32 +22697,24 @@ class ContainerImage(
22674
22697
 
22675
22698
  Example::
22676
22699
 
22677
- # vpc: ec2.Vpc
22700
+ # my_file_system: efs.IFileSystem
22701
+ # my_job_role: iam.Role
22678
22702
 
22703
+ my_file_system.grant_read(my_job_role)
22679
22704
 
22680
- cluster = ecs.Cluster(self, "FargateCPCluster",
22681
- vpc=vpc,
22682
- enable_fargate_capacity_providers=True
22683
- )
22684
-
22685
- task_definition = ecs.FargateTaskDefinition(self, "TaskDef")
22686
-
22687
- task_definition.add_container("web",
22688
- image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
22689
- )
22690
-
22691
- ecs.FargateService(self, "FargateService",
22692
- cluster=cluster,
22693
- task_definition=task_definition,
22694
- min_healthy_percent=100,
22695
- capacity_provider_strategies=[ecs.CapacityProviderStrategy(
22696
- capacity_provider="FARGATE_SPOT",
22697
- weight=2
22698
- ), ecs.CapacityProviderStrategy(
22699
- capacity_provider="FARGATE",
22700
- weight=1
22705
+ job_defn = batch.EcsJobDefinition(self, "JobDefn",
22706
+ container=batch.EcsEc2ContainerDefinition(self, "containerDefn",
22707
+ image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
22708
+ memory=cdk.Size.mebibytes(2048),
22709
+ cpu=256,
22710
+ volumes=[batch.EcsVolume.efs(
22711
+ name="myVolume",
22712
+ file_system=my_file_system,
22713
+ container_path="/Volumes/myVolume",
22714
+ use_job_role=True
22715
+ )],
22716
+ job_role=my_job_role
22701
22717
  )
22702
- ]
22703
22718
  )
22704
22719
  '''
22705
22720
 
@@ -24372,18 +24387,31 @@ class Ec2ServiceProps(BaseServiceOptions):
24372
24387
 
24373
24388
  Example::
24374
24389
 
24375
- # cluster: ecs.Cluster
24376
- # task_definition: ecs.TaskDefinition
24377
24390
  # vpc: ec2.Vpc
24378
24391
 
24379
- service = ecs.Ec2Service(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)
24380
24392
 
24381
- lb = elb.LoadBalancer(self, "LB", vpc=vpc)
24382
- lb.add_listener(external_port=80)
24383
- lb.add_target(service.load_balancer_target(
24384
- container_name="MyContainer",
24385
- container_port=80
24386
- ))
24393
+ # Create an ECS cluster
24394
+ cluster = ecs.Cluster(self, "Cluster", vpc=vpc)
24395
+
24396
+ # Add capacity to it
24397
+ cluster.add_capacity("DefaultAutoScalingGroupCapacity",
24398
+ instance_type=ec2.InstanceType("t2.xlarge"),
24399
+ desired_capacity=3
24400
+ )
24401
+
24402
+ task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")
24403
+
24404
+ task_definition.add_container("DefaultContainer",
24405
+ image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
24406
+ memory_limit_mi_b=512
24407
+ )
24408
+
24409
+ # Instantiate an Amazon ECS Service
24410
+ ecs_service = ecs.Ec2Service(self, "Service",
24411
+ cluster=cluster,
24412
+ task_definition=task_definition,
24413
+ min_healthy_percent=100
24414
+ )
24387
24415
  '''
24388
24416
  if isinstance(circuit_breaker, dict):
24389
24417
  circuit_breaker = DeploymentCircuitBreaker(**circuit_breaker)
@@ -24927,13 +24955,14 @@ class Ec2TaskDefinitionProps(CommonTaskDefinitionProps):
24927
24955
 
24928
24956
  Example::
24929
24957
 
24930
- inference_accelerators = [{
24931
- "device_name": "device1",
24932
- "device_type": "eia2.medium"
24933
- }]
24958
+ ec2_task_definition = ecs.Ec2TaskDefinition(self, "TaskDef",
24959
+ network_mode=ecs.NetworkMode.BRIDGE
24960
+ )
24934
24961
 
24935
- task_definition = ecs.Ec2TaskDefinition(self, "Ec2TaskDef",
24936
- inference_accelerators=inference_accelerators
24962
+ container = ec2_task_definition.add_container("WebContainer",
24963
+ # Use an image from DockerHub
24964
+ image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
24965
+ memory_limit_mi_b=1024
24937
24966
  )
24938
24967
  '''
24939
24968
  if __debug__:
@@ -27180,21 +27209,39 @@ class FargateServiceProps(BaseServiceOptions):
27180
27209
 
27181
27210
  Example::
27182
27211
 
27212
+ import aws_cdk.aws_cloudwatch as cw
27213
+
27183
27214
  # cluster: ecs.Cluster
27184
27215
  # task_definition: ecs.TaskDefinition
27185
- # vpc: ec2.Vpc
27186
27216
 
27187
- service = ecs.FargateService(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)
27217
+ service_name = "MyFargateService"
27218
+ service = ecs.FargateService(self, "Service",
27219
+ service_name=service_name,
27220
+ cluster=cluster,
27221
+ task_definition=task_definition,
27222
+ min_healthy_percent=100
27223
+ )
27188
27224
 
27189
- lb = elbv2.ApplicationLoadBalancer(self, "LB", vpc=vpc, internet_facing=True)
27190
- listener = lb.add_listener("Listener", port=80)
27191
- service.register_load_balancer_targets(
27192
- container_name="web",
27193
- container_port=80,
27194
- new_target_group_id="ECS",
27195
- listener=ecs.ListenerConfig.application_listener(listener,
27196
- protocol=elbv2.ApplicationProtocol.HTTPS
27197
- )
27225
+ cpu_metric = cw.Metric(
27226
+ metric_name="CPUUtilization",
27227
+ namespace="AWS/ECS",
27228
+ period=Duration.minutes(5),
27229
+ statistic="Average",
27230
+ dimensions_map={
27231
+ "ClusterName": cluster.cluster_name,
27232
+ # Using `service.serviceName` here will cause a circular dependency
27233
+ "ServiceName": service_name
27234
+ }
27235
+ )
27236
+ my_alarm = cw.Alarm(self, "CPUAlarm",
27237
+ alarm_name="cpuAlarmName",
27238
+ metric=cpu_metric,
27239
+ evaluation_periods=2,
27240
+ threshold=80
27241
+ )
27242
+
27243
+ service.enable_deployment_alarms([my_alarm.alarm_name],
27244
+ behavior=ecs.AlarmBehavior.FAIL_ON_ALARM
27198
27245
  )
27199
27246
  '''
27200
27247
  if isinstance(circuit_breaker, dict):
@@ -27699,14 +27746,20 @@ class FargateTaskDefinitionProps(CommonTaskDefinitionProps):
27699
27746
 
27700
27747
  Example::
27701
27748
 
27702
- fargate_task_definition = ecs.FargateTaskDefinition(self, "TaskDef",
27749
+ # Create a Task Definition for the Windows container to start
27750
+ task_definition = ecs.FargateTaskDefinition(self, "TaskDef",
27703
27751
  runtime_platform=ecs.RuntimePlatform(
27704
- operating_system_family=ecs.OperatingSystemFamily.LINUX,
27705
- cpu_architecture=ecs.CpuArchitecture.ARM64
27752
+ operating_system_family=ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_CORE,
27753
+ cpu_architecture=ecs.CpuArchitecture.X86_64
27706
27754
  ),
27707
- memory_limit_mi_b=512,
27708
- cpu=256,
27709
- pid_mode=ecs.PidMode.TASK
27755
+ cpu=1024,
27756
+ memory_limit_mi_b=2048
27757
+ )
27758
+
27759
+ task_definition.add_container("windowsservercore",
27760
+ logging=ecs.LogDriver.aws_logs(stream_prefix="win-iis-on-fargate"),
27761
+ port_mappings=[ecs.PortMapping(container_port=80)],
27762
+ image=ecs.ContainerImage.from_registry("mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019")
27710
27763
  )
27711
27764
  '''
27712
27765
  if isinstance(runtime_platform, dict):
@@ -35281,22 +35334,29 @@ class ServiceConnectProps:
35281
35334
 
35282
35335
  # cluster: ecs.Cluster
35283
35336
  # task_definition: ecs.TaskDefinition
35337
+ # container_options: ecs.ContainerDefinitionOptions
35338
+
35339
+
35340
+ container = task_definition.add_container("MyContainer", container_options)
35341
+
35342
+ container.add_port_mappings(
35343
+ name="api",
35344
+ container_port=8080
35345
+ )
35284
35346
 
35347
+ cluster.add_default_cloud_map_namespace(
35348
+ name="local"
35349
+ )
35285
35350
 
35286
- custom_service = ecs.FargateService(self, "CustomizedService",
35351
+ service = ecs.FargateService(self, "Service",
35287
35352
  cluster=cluster,
35288
35353
  task_definition=task_definition,
35289
35354
  min_healthy_percent=100,
35290
35355
  service_connect_configuration=ecs.ServiceConnectProps(
35291
- log_driver=ecs.LogDrivers.aws_logs(
35292
- stream_prefix="sc-traffic"
35293
- ),
35294
35356
  services=[ecs.ServiceConnectService(
35295
35357
  port_mapping_name="api",
35296
- dns_name="customized-api",
35297
- port=80,
35298
- ingress_port_override=20040,
35299
- discovery_name="custom"
35358
+ dns_name="http-api",
35359
+ port=80
35300
35360
  )
35301
35361
  ]
35302
35362
  )
@@ -37234,28 +37294,21 @@ class TaskDefinition(
37234
37294
 
37235
37295
  Example::
37236
37296
 
37237
- import aws_cdk.aws_cloudwatch as cw
37238
-
37239
37297
  # cluster: ecs.Cluster
37240
37298
  # task_definition: ecs.TaskDefinition
37299
+ # vpc: ec2.Vpc
37241
37300
 
37301
+ service = ecs.FargateService(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)
37242
37302
 
37243
- service = ecs.FargateService(self, "Service",
37244
- cluster=cluster,
37245
- task_definition=task_definition
37246
- )
37247
-
37248
- cpu_alarm_name = "MyCpuMetricAlarm"
37249
- my_alarm = cw.Alarm(self, "CPUAlarm",
37250
- alarm_name=cpu_alarm_name,
37251
- metric=service.metric_cpu_utilization(),
37252
- evaluation_periods=2,
37253
- threshold=80
37254
- )
37255
-
37256
- # Using `myAlarm.alarmName` here will cause a circular dependency
37257
- service.enable_deployment_alarms([cpu_alarm_name],
37258
- behavior=ecs.AlarmBehavior.FAIL_ON_ALARM
37303
+ lb = elbv2.ApplicationLoadBalancer(self, "LB", vpc=vpc, internet_facing=True)
37304
+ listener = lb.add_listener("Listener", port=80)
37305
+ service.register_load_balancer_targets(
37306
+ container_name="web",
37307
+ container_port=80,
37308
+ new_target_group_id="ECS",
37309
+ listener=ecs.ListenerConfig.application_listener(listener,
37310
+ protocol=elbv2.ApplicationProtocol.HTTPS
37311
+ )
37259
37312
  )
37260
37313
  '''
37261
37314
 
@@ -39648,31 +39701,24 @@ class Cluster(
39648
39701
 
39649
39702
  Example::
39650
39703
 
39651
- import aws_cdk.aws_elasticloadbalancingv2 as elbv2
39704
+ from aws_cdk import Tags
39652
39705
 
39653
39706
 
39654
- # The VPC and subnet must have associated IPv6 CIDR blocks.
39655
- vpc = ec2.Vpc(self, "Vpc",
39656
- ip_protocol=ec2.IpProtocol.DUAL_STACK
39657
- )
39707
+ vpc = ec2.Vpc(self, "Vpc", max_azs=1)
39658
39708
  cluster = ecs.Cluster(self, "EcsCluster", vpc=vpc)
39659
-
39660
- service = ecs_patterns.ApplicationLoadBalancedFargateService(self, "myService",
39661
- cluster=cluster,
39662
- task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
39663
- image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
39664
- ),
39665
- min_healthy_percent=100,
39666
- ip_address_type=elbv2.IpAddressType.DUAL_STACK
39709
+ task_definition = ecs.FargateTaskDefinition(self, "TaskDef",
39710
+ memory_limit_mi_b=512,
39711
+ cpu=256
39667
39712
  )
39668
-
39669
- application_load_balanced_ec2_service = ecs_patterns.ApplicationLoadBalancedEc2Service(self, "myService",
39713
+ task_definition.add_container("WebContainer",
39714
+ image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
39715
+ )
39716
+ Tags.of(task_definition).add("my-tag", "my-tag-value")
39717
+ scheduled_fargate_task = ecs_patterns.ScheduledFargateTask(self, "ScheduledFargateTask",
39670
39718
  cluster=cluster,
39671
- task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
39672
- image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
39673
- ),
39674
- min_healthy_percent=100,
39675
- ip_address_type=elbv2.IpAddressType.DUAL_STACK
39719
+ task_definition=task_definition,
39720
+ schedule=appscaling.Schedule.expression("rate(1 minute)"),
39721
+ propagate_tags=ecs.PropagatedTagSource.TASK_DEFINITION
39676
39722
  )
39677
39723
  '''
39678
39724
 
@@ -41663,18 +41709,31 @@ class Ec2Service(
41663
41709
 
41664
41710
  Example::
41665
41711
 
41666
- # cluster: ecs.Cluster
41667
- # task_definition: ecs.TaskDefinition
41668
41712
  # vpc: ec2.Vpc
41669
41713
 
41670
- service = ecs.Ec2Service(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)
41671
41714
 
41672
- lb = elb.LoadBalancer(self, "LB", vpc=vpc)
41673
- lb.add_listener(external_port=80)
41674
- lb.add_target(service.load_balancer_target(
41675
- container_name="MyContainer",
41676
- container_port=80
41677
- ))
41715
+ # Create an ECS cluster
41716
+ cluster = ecs.Cluster(self, "Cluster", vpc=vpc)
41717
+
41718
+ # Add capacity to it
41719
+ cluster.add_capacity("DefaultAutoScalingGroupCapacity",
41720
+ instance_type=ec2.InstanceType("t2.xlarge"),
41721
+ desired_capacity=3
41722
+ )
41723
+
41724
+ task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")
41725
+
41726
+ task_definition.add_container("DefaultContainer",
41727
+ image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
41728
+ memory_limit_mi_b=512
41729
+ )
41730
+
41731
+ # Instantiate an Amazon ECS Service
41732
+ ecs_service = ecs.Ec2Service(self, "Service",
41733
+ cluster=cluster,
41734
+ task_definition=task_definition,
41735
+ min_healthy_percent=100
41736
+ )
41678
41737
  '''
41679
41738
 
41680
41739
  def __init__(
@@ -41879,17 +41938,15 @@ class Ec2TaskDefinition(
41879
41938
 
41880
41939
  Example::
41881
41940
 
41882
- # secret: ecs.Secret
41883
-
41884
-
41885
41941
  # Create a Task Definition for the container to start
41886
41942
  task_definition = ecs.Ec2TaskDefinition(self, "TaskDef")
41887
41943
  task_definition.add_container("TheContainer",
41888
41944
  image=ecs.ContainerImage.from_registry("example-image"),
41889
41945
  memory_limit_mi_b=256,
41890
- logging=ecs.LogDrivers.splunk(
41891
- secret_token=secret,
41892
- url="my-splunk-url"
41946
+ logging=ecs.LogDrivers.aws_logs(
41947
+ stream_prefix="EventDemo",
41948
+ mode=ecs.AwsLogDriverMode.NON_BLOCKING,
41949
+ max_buffer_size=Size.mebibytes(25)
41893
41950
  )
41894
41951
  )
41895
41952
  '''
@@ -42593,21 +42650,39 @@ class FargateService(
42593
42650
 
42594
42651
  Example::
42595
42652
 
42653
+ import aws_cdk.aws_cloudwatch as cw
42654
+
42596
42655
  # cluster: ecs.Cluster
42597
42656
  # task_definition: ecs.TaskDefinition
42598
- # vpc: ec2.Vpc
42599
42657
 
42600
- service = ecs.FargateService(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)
42658
+ service_name = "MyFargateService"
42659
+ service = ecs.FargateService(self, "Service",
42660
+ service_name=service_name,
42661
+ cluster=cluster,
42662
+ task_definition=task_definition,
42663
+ min_healthy_percent=100
42664
+ )
42601
42665
 
42602
- lb = elbv2.ApplicationLoadBalancer(self, "LB", vpc=vpc, internet_facing=True)
42603
- listener = lb.add_listener("Listener", port=80)
42604
- service.register_load_balancer_targets(
42605
- container_name="web",
42606
- container_port=80,
42607
- new_target_group_id="ECS",
42608
- listener=ecs.ListenerConfig.application_listener(listener,
42609
- protocol=elbv2.ApplicationProtocol.HTTPS
42610
- )
42666
+ cpu_metric = cw.Metric(
42667
+ metric_name="CPUUtilization",
42668
+ namespace="AWS/ECS",
42669
+ period=Duration.minutes(5),
42670
+ statistic="Average",
42671
+ dimensions_map={
42672
+ "ClusterName": cluster.cluster_name,
42673
+ # Using `service.serviceName` here will cause a circular dependency
42674
+ "ServiceName": service_name
42675
+ }
42676
+ )
42677
+ my_alarm = cw.Alarm(self, "CPUAlarm",
42678
+ alarm_name="cpuAlarmName",
42679
+ metric=cpu_metric,
42680
+ evaluation_periods=2,
42681
+ threshold=80
42682
+ )
42683
+
42684
+ service.enable_deployment_alarms([my_alarm.alarm_name],
42685
+ behavior=ecs.AlarmBehavior.FAIL_ON_ALARM
42611
42686
  )
42612
42687
  '''
42613
42688