Class PlacementConstraint
The placement constraints to use for tasks in the service. For more information, see Amazon ECS Task Placement Constraints.
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class PlacementConstraint : DeputyBase
Syntax (vb)
Public Class PlacementConstraint Inherits DeputyBase
Remarks
Tasks will only be placed on instances that match these rules.
ExampleMetadata: infused
Examples
var vpc = Vpc.FromLookup(this, "Vpc", new VpcLookupOptions {
IsDefault = true
});
var cluster = new Cluster(this, "Ec2Cluster", new ClusterProps { Vpc = vpc });
cluster.AddCapacity("DefaultAutoScalingGroup", new AddCapacityOptions {
InstanceType = new InstanceType("t2.micro"),
VpcSubnets = new SubnetSelection { SubnetType = SubnetType.PUBLIC }
});
var taskDefinition = new TaskDefinition(this, "TD", new TaskDefinitionProps {
Compatibility = Compatibility.EC2
});
taskDefinition.AddContainer("TheContainer", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("foo/bar"),
MemoryLimitMiB = 256
});
var runTask = new EcsRunTask(this, "Run", new EcsRunTaskProps {
IntegrationPattern = IntegrationPattern.RUN_JOB,
Cluster = cluster,
TaskDefinition = taskDefinition,
LaunchTarget = new EcsEc2LaunchTarget(new EcsEc2LaunchTargetOptions {
PlacementStrategies = new [] { PlacementStrategy.SpreadAcrossInstances(), PlacementStrategy.PackedByCpu(), PlacementStrategy.Randomly() },
PlacementConstraints = new [] { PlacementConstraint.MemberOf("blieptuut") }
}),
PropagatedTagSource = PropagatedTagSource.TASK_DEFINITION
});
Synopsis
Methods
DistinctInstances() | Use distinctInstance to ensure that each task in a particular group is running on a different container instance. |
MemberOf(params string[]) | Use memberOf to restrict the selection to a group of valid candidates specified by a query expression. |
ToJson() | Return the placement JSON. |
Methods
DistinctInstances()
Use distinctInstance to ensure that each task in a particular group is running on a different container instance.
public static PlacementConstraint DistinctInstances()
Returns
Remarks
Tasks will only be placed on instances that match these rules.
ExampleMetadata: infused
MemberOf(params string[])
Use memberOf to restrict the selection to a group of valid candidates specified by a query expression.
public static PlacementConstraint MemberOf(params string[] expressions)
Parameters
- expressions string[]
Returns
Remarks
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.
ToJson()
Return the placement JSON.
public virtual CfnService.IPlacementConstraintProperty[] ToJson()
Returns
IPlacementConstraintProperty[]
Remarks
Tasks will only be placed on instances that match these rules.
ExampleMetadata: infused