Class AsgCapacityProvider

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.services.ecs.AsgCapacityProvider
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.95.0 (build f1ff514)", date="2024-03-26T18:09:22.990Z") @Stability(Stable) public class AsgCapacityProvider extends software.constructs.Construct
An Auto Scaling Group Capacity Provider.

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();
 // Either add default capacity
 cluster.addCapacity("DefaultAutoScalingGroupCapacity", AddCapacityOptions.builder()
         .instanceType(new InstanceType("t2.xlarge"))
         .desiredCapacity(3)
         .build());
 // Or add customized capacity. Be sure to start the Amazon ECS-optimized AMI.
 AutoScalingGroup autoScalingGroup = AutoScalingGroup.Builder.create(this, "ASG")
         .vpc(vpc)
         .instanceType(new InstanceType("t2.xlarge"))
         .machineImage(EcsOptimizedImage.amazonLinux())
         // Or use Amazon ECS-Optimized Amazon Linux 2 AMI
         // machineImage: EcsOptimizedImage.amazonLinux2(),
         .desiredCapacity(3)
         .build();
 AsgCapacityProvider capacityProvider = AsgCapacityProvider.Builder.create(this, "AsgCapacityProvider")
         .autoScalingGroup(autoScalingGroup)
         .build();
 cluster.addAsgCapacityProvider(capacityProvider);
 
  • Constructor Details

    • AsgCapacityProvider

      protected AsgCapacityProvider(software.amazon.jsii.JsiiObjectRef objRef)
    • AsgCapacityProvider

      protected AsgCapacityProvider(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • AsgCapacityProvider

      @Stability(Stable) public AsgCapacityProvider(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull AsgCapacityProviderProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • getAutoScalingGroup

      @Stability(Stable) @NotNull public AutoScalingGroup getAutoScalingGroup()
      Auto Scaling Group.
    • getCapacityProviderName

      @Stability(Stable) @NotNull public String getCapacityProviderName()
      Capacity provider name.

      Default: Chosen by CloudFormation

    • getMachineImageType

      @Stability(Stable) @NotNull public MachineImageType getMachineImageType()
      Auto Scaling Group machineImageType.
    • getCanContainersAccessInstanceRole

      @Stability(Stable) @Nullable public Boolean getCanContainersAccessInstanceRole()
      Specifies whether the containers can access the container instance role.

      Default: false

    • getEnableManagedDraining

      @Stability(Stable) @Nullable public Boolean getEnableManagedDraining()
      Whether managed draining is enabled.
    • getEnableManagedTerminationProtection

      @Stability(Stable) @Nullable public Boolean getEnableManagedTerminationProtection()
      Whether managed termination protection is enabled.