Class PlacementStrategy
The placement strategies to use for tasks in the service. For more information, see Amazon ECS Task Placement Strategies.
Inheritance
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class PlacementStrategy : DeputyBase
Syntax (vb)
Public Class PlacementStrategy
Inherits DeputyBase
Remarks
Tasks will preferentially 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
PlacementStrategy(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
PlacementStrategy(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
PackedBy(BinPackResource) | Places tasks on the container instances with the least available capacity of the specified resource. |
PackedByCpu() | Places tasks on container instances with the least available amount of CPU capacity. |
PackedByMemory() | Places tasks on container instances with the least available amount of memory capacity. |
Randomly() | Places tasks randomly. |
SpreadAcross(String[]) | Places tasks evenly based on the specified value. |
SpreadAcrossInstances() | Places tasks evenly across all container instances in the cluster. |
ToJson() | Return the placement JSON. |
Constructors
PlacementStrategy(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected PlacementStrategy(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
PlacementStrategy(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected PlacementStrategy(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
PackedBy(BinPackResource)
Places tasks on the container instances with the least available capacity of the specified resource.
public static PlacementStrategy PackedBy(BinPackResource resource)
Parameters
- resource BinPackResource
Returns
PackedByCpu()
Places tasks on container instances with the least available amount of CPU capacity.
public static PlacementStrategy PackedByCpu()
Returns
Remarks
This minimizes the number of instances in use.
PackedByMemory()
Places tasks on container instances with the least available amount of memory capacity.
public static PlacementStrategy PackedByMemory()
Returns
Remarks
This minimizes the number of instances in use.
Randomly()
SpreadAcross(String[])
Places tasks evenly based on the specified value.
public static PlacementStrategy SpreadAcross(params string[] fields)
Parameters
- fields System.String[]
Returns
Remarks
You can use one of the built-in attributes found on BuiltInAttributes
or supply your own custom instance attributes. If more than one attribute
is supplied, spreading is done in order.
Default: attributes instanceId
SpreadAcrossInstances()
Places tasks evenly across all container instances in the cluster.
public static PlacementStrategy SpreadAcrossInstances()
Returns
ToJson()
Return the placement JSON.
public virtual CfnService.IPlacementStrategyProperty[] ToJson()
Returns
CfnService.IPlacementStrategyProperty[]