Class PlacementStrategy
java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.ecs.PlacementStrategy
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.104.0 (build e79254c)",
date="2024-11-22T02:24:01.150Z")
@Stability(Stable)
public class PlacementStrategy
extends software.amazon.jsii.JsiiObject
The placement strategies to use for tasks in the service. For more information, see Amazon ECS Task Placement Strategies.
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()) .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
PlacementStrategy
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
PlacementStrategy
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Modifier and TypeMethodDescriptionstatic PlacementStrategy
packedBy
(BinPackResource resource) Places tasks on the container instances with the least available capacity of the specified resource.static PlacementStrategy
Places tasks on container instances with the least available amount of CPU capacity.static PlacementStrategy
Places tasks on container instances with the least available amount of memory capacity.static PlacementStrategy
randomly()
Places tasks randomly.static PlacementStrategy
spreadAcross
(@NotNull String... fields) Places tasks evenly based on the specified value.static PlacementStrategy
Places tasks evenly across all container instances in the cluster.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
-
PlacementStrategy
protected PlacementStrategy(software.amazon.jsii.JsiiObjectRef objRef) -
PlacementStrategy
protected PlacementStrategy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
-
-
Method Details
-
packedBy
@Stability(Stable) @NotNull public static PlacementStrategy packedBy(@NotNull BinPackResource resource) Places tasks on the container instances with the least available capacity of the specified resource.- Parameters:
resource
- This parameter is required.
-
packedByCpu
Places tasks on container instances with the least available amount of CPU capacity.This minimizes the number of instances in use.
-
packedByMemory
Places tasks on container instances with the least available amount of memory capacity.This minimizes the number of instances in use.
-
randomly
Places tasks randomly. -
spreadAcross
@Stability(Stable) @NotNull public static PlacementStrategy spreadAcross(@NotNull @NotNull String... fields) Places tasks evenly based on the specified value.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
- Parameters:
fields
- This parameter is required.
-
spreadAcrossInstances
Places tasks evenly across all container instances in the cluster. -
toJson
Return the placement JSON.
-