Class PlacementConstraint
The placement constraints to use for tasks in the service. For more information, see Amazon ECS Task Placement Constraints.
Inheritance
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
Constructors
Placement |
Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Placement |
Used by jsii to construct an instance of this class from DeputyProps |
Methods
Distinct |
Use distinctInstance to ensure that each task in a particular group is running on a different container instance. |
Member |
Use memberOf to restrict the selection to a group of valid candidates specified by a query expression. |
To |
Return the placement JSON. |
Constructors
PlacementConstraint(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected PlacementConstraint(ByRefValue reference)
Parameters
- reference Amazon.
JSII. Runtime. Deputy. By Ref Value The Javascript-owned object reference
PlacementConstraint(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected PlacementConstraint(DeputyBase.DeputyProps props)
Parameters
- props Amazon.
JSII. Runtime. Deputy. Deputy Base. Deputy Props The deputy props
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
MemberOf(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 System.
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.
See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html
ToJson()
Return the placement JSON.
public virtual CfnService.IPlacementConstraintProperty[] ToJson()
Returns
Cfn