@Generated(value="jsii-pacmak/1.73.0 (build 6faeda3)",
date="2023-01-31T18:37:00.435Z")
public class PlacementStrategy
extends software.amazon.jsii.JsiiObject
Tasks will preferentially 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()) .build();
Modifier | Constructor and Description |
---|---|
protected |
PlacementStrategy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
PlacementStrategy(software.amazon.jsii.JsiiObjectRef objRef) |
Modifier and Type | Method and Description |
---|---|
static PlacementStrategy |
packedBy(BinPackResource resource)
Places tasks on the container instances with the least available capacity of the specified resource.
|
static PlacementStrategy |
packedByCpu()
Places tasks on container instances with the least available amount of CPU capacity.
|
static PlacementStrategy |
packedByMemory()
Places tasks on container instances with the least available amount of memory capacity.
|
static PlacementStrategy |
randomly()
Places tasks randomly.
|
static PlacementStrategy |
spreadAcross(java.lang.String... fields)
Places tasks evenly based on the specified value.
|
static PlacementStrategy |
spreadAcrossInstances()
Places tasks evenly across all container instances in the cluster.
|
java.util.List<CfnService.PlacementStrategyProperty> |
toJson()
Return the placement JSON.
|
protected PlacementStrategy(software.amazon.jsii.JsiiObjectRef objRef)
protected PlacementStrategy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
public static PlacementStrategy packedBy(BinPackResource resource)
resource
- This parameter is required.public static PlacementStrategy packedByCpu()
This minimizes the number of instances in use.
public static PlacementStrategy packedByMemory()
This minimizes the number of instances in use.
public static PlacementStrategy randomly()
public static PlacementStrategy spreadAcross(java.lang.String... fields)
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
fields
- This parameter is required.public static PlacementStrategy spreadAcrossInstances()
public java.util.List<CfnService.PlacementStrategyProperty> toJson()