Class PlacementConstraint
java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.ecs.PlacementConstraint
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.103.1 (build bef2dea)",
date="2024-10-25T14:21:14.665Z")
@Stability(Stable)
public class PlacementConstraint
extends software.amazon.jsii.JsiiObject
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.
Example:
IVpc vpc = Vpc.fromLookup(this, "Vpc", VpcLookupOptions.builder() .isDefault(true) .build()); Cluster cluster = Cluster.Builder.create(this, "Ec2Cluster").vpc(vpc).build(); cluster.addCapacity("DefaultAutoScalingGroup", AddCapacityOptions.builder() .instanceType(new InstanceType("t2.micro")) .vpcSubnets(SubnetSelection.builder().subnetType(SubnetType.PUBLIC).build()) .build()); TaskDefinition taskDefinition = TaskDefinition.Builder.create(this, "TD") .compatibility(Compatibility.EC2) .build(); taskDefinition.addContainer("TheContainer", ContainerDefinitionOptions.builder() .image(ContainerImage.fromRegistry("foo/bar")) .memoryLimitMiB(256) .build()); EcsRunTask runTask = EcsRunTask.Builder.create(this, "Run") .integrationPattern(IntegrationPattern.RUN_JOB) .cluster(cluster) .taskDefinition(taskDefinition) .launchTarget(EcsEc2LaunchTarget.Builder.create() .placementStrategies(List.of(PlacementStrategy.spreadAcrossInstances(), PlacementStrategy.packedByCpu(), PlacementStrategy.randomly())) .placementConstraints(List.of(PlacementConstraint.memberOf("blieptuut"))) .build()) .propagatedTagSource(PropagatedTagSource.TASK_DEFINITION) .build();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Constructor Summary
ModifierConstructorDescriptionprotected
PlacementConstraint
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
PlacementConstraint
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Modifier and TypeMethodDescriptionstatic PlacementConstraint
Use distinctInstance to ensure that each task in a particular group is running on a different container instance.static PlacementConstraint
Use memberOf to restrict the selection to a group of valid candidates specified by a query expression.toJson()
Return the placement JSON.Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
PlacementConstraint
protected PlacementConstraint(software.amazon.jsii.JsiiObjectRef objRef) -
PlacementConstraint
protected PlacementConstraint(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
-
-
Method Details
-
distinctInstances
Use distinctInstance to ensure that each task in a particular group is running on a different container instance. -
memberOf
@Stability(Stable) @NotNull public static PlacementConstraint memberOf(@NotNull @NotNull String... 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
- This parameter is required.- See Also:
-
toJson
Return the placement JSON.
-