PlacementConstraint
- class aws_cdk.aws_ecs.PlacementConstraint(*args: Any, **kwargs)
Bases:
object
The placement constraints to use for tasks in the service. For more information, see Amazon ECS Task Placement Constraints.
Tasks will only be placed on instances that match these rules.
- ExampleMetadata:
infused
Example:
vpc = ec2.Vpc.from_lookup(self, "Vpc", is_default=True ) cluster = ecs.Cluster(self, "Ec2Cluster", vpc=vpc) cluster.add_capacity("DefaultAutoScalingGroup", instance_type=ec2.InstanceType("t2.micro"), vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC) ) task_definition = ecs.TaskDefinition(self, "TD", compatibility=ecs.Compatibility.EC2 ) task_definition.add_container("TheContainer", image=ecs.ContainerImage.from_registry("foo/bar"), memory_limit_mi_b=256 ) run_task = tasks.EcsRunTask(self, "Run", integration_pattern=sfn.IntegrationPattern.RUN_JOB, cluster=cluster, task_definition=task_definition, launch_target=tasks.EcsEc2LaunchTarget( placement_strategies=[ ecs.PlacementStrategy.spread_across_instances(), ecs.PlacementStrategy.packed_by_cpu(), ecs.PlacementStrategy.randomly() ], placement_constraints=[ ecs.PlacementConstraint.member_of("blieptuut") ] ) )
Methods
- to_json()
Return the placement JSON.
- Return type:
Static Methods
- classmethod distinct_instances()
Use distinctInstance to ensure that each task in a particular group is running on a different container instance.
- Return type:
- classmethod member_of(*expressions)
Use memberOf to restrict the selection to a group of valid candidates specified by a query expression.
Multiple expressions can be specified. For more information, see Cluster Query Language.
You can specify multiple expressions in one call. The tasks will only be placed on instances matching all expressions.
- Parameters:
expressions (
str
) –- See:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html
- Return type: