@Generated(value="jsii-pacmak/1.60.0 (build ebcefe6)", date="2022-06-22T23:28:01.252Z") public class AsgCapacityProvider extends Construct
This allows an ECS cluster to target a specific EC2 Auto Scaling Group for the placement of tasks. Optionally (and recommended), ECS can manage the number of instances in the ASG to fit the tasks, and can ensure that instances are not prematurely terminated while there are still tasks running on them.
Example:
Vpc vpc; Cluster cluster = Cluster.Builder.create(this, "Cluster") .vpc(vpc) .build(); AutoScalingGroup autoScalingGroup = AutoScalingGroup.Builder.create(this, "ASG") .vpc(vpc) .instanceType(new InstanceType("t2.micro")) .machineImage(EcsOptimizedImage.amazonLinux2()) .minCapacity(0) .maxCapacity(100) .build(); AsgCapacityProvider capacityProvider = AsgCapacityProvider.Builder.create(this, "AsgCapacityProvider") .autoScalingGroup(autoScalingGroup) .build(); cluster.addAsgCapacityProvider(capacityProvider); Ec2TaskDefinition taskDefinition = new Ec2TaskDefinition(this, "TaskDef"); taskDefinition.addContainer("web", ContainerDefinitionOptions.builder() .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample")) .memoryReservationMiB(256) .build()); Ec2Service.Builder.create(this, "EC2Service") .cluster(cluster) .taskDefinition(taskDefinition) .capacityProviderStrategies(List.of(CapacityProviderStrategy.builder() .capacityProvider(capacityProvider.getCapacityProviderName()) .weight(1) .build())) .build();
Modifier and Type | Class and Description |
---|---|
static class |
AsgCapacityProvider.Builder
A fluent builder for
AsgCapacityProvider . |
IConstruct.Jsii$Default, IConstruct.Jsii$Proxy
Modifier | Constructor and Description |
---|---|
protected |
AsgCapacityProvider(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
AsgCapacityProvider(software.amazon.jsii.JsiiObjectRef objRef) |
|
AsgCapacityProvider(software.constructs.Construct scope,
java.lang.String id,
AsgCapacityProviderProps props) |
Modifier and Type | Method and Description |
---|---|
AutoScalingGroup |
getAutoScalingGroup()
Auto Scaling Group.
|
java.lang.Boolean |
getCanContainersAccessInstanceRole()
Specifies whether the containers can access the container instance role.
|
java.lang.String |
getCapacityProviderName()
Capacity provider name.
|
java.lang.Boolean |
getEnableManagedTerminationProtection()
Whether managed termination protection is enabled.
|
MachineImageType |
getMachineImageType()
Auto Scaling Group machineImageType.
|
getNode, isConstruct, onPrepare, onSynthesize, onValidate, prepare, synthesize, validate
protected AsgCapacityProvider(software.amazon.jsii.JsiiObjectRef objRef)
protected AsgCapacityProvider(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
public AsgCapacityProvider(software.constructs.Construct scope, java.lang.String id, AsgCapacityProviderProps props)
scope
- This parameter is required.id
- This parameter is required.props
- This parameter is required.public AutoScalingGroup getAutoScalingGroup()
public java.lang.String getCapacityProviderName()
Default: Chosen by CloudFormation
public MachineImageType getMachineImageType()
public java.lang.Boolean getCanContainersAccessInstanceRole()
Default: false
public java.lang.Boolean getEnableManagedTerminationProtection()