Class AutoScalingGroup

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.core.Construct
software.amazon.awscdk.core.Resource
software.amazon.awscdk.services.autoscaling.AutoScalingGroup
All Implemented Interfaces:
IConstruct, IDependable, IResource, IAutoScalingGroup, IConnectable, ILoadBalancerTarget, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, IGrantable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:45.163Z") @Stability(Stable) public class AutoScalingGroup extends Resource implements ILoadBalancerTarget, IConnectable, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, IAutoScalingGroup
A Fleet represents a managed set of EC2 instances.

The Fleet models a number of AutoScalingGroups, a launch configuration, a security group and an instance role.

It allows adding arbitrary commands to the startup scripts of the instances in the fleet.

The ASG spans the availability zones specified by vpcSubnets, falling back to the Vpc default strategy if not specified.

Example:

 Vpc vpc;
 SecurityGroup mySecurityGroup = SecurityGroup.Builder.create(this, "SecurityGroup").vpc(vpc).build();
 AutoScalingGroup.Builder.create(this, "ASG")
         .vpc(vpc)
         .instanceType(InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO))
         .machineImage(new AmazonLinuxImage())
         .securityGroup(mySecurityGroup)
         .build();
 
  • Constructor Details

    • AutoScalingGroup

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

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

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

    • fromAutoScalingGroupName

      @Stability(Stable) @NotNull public static IAutoScalingGroup fromAutoScalingGroupName(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String autoScalingGroupName)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      autoScalingGroupName - This parameter is required.
    • addLifecycleHook

      @Stability(Stable) @NotNull public LifecycleHook addLifecycleHook(@NotNull String id, @NotNull BasicLifecycleHookProps props)
      Send a message to either an SQS queue or SNS topic when instances launch or terminate.

      Specified by:
      addLifecycleHook in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • addSecurityGroup

      @Stability(Stable) public void addSecurityGroup(@NotNull ISecurityGroup securityGroup)
      Add the security group to all instances via the launch configuration security groups array.

      Parameters:
      securityGroup - : The security group to add. This parameter is required.
    • addToRolePolicy

      @Stability(Stable) public void addToRolePolicy(@NotNull PolicyStatement statement)
      Adds a statement to the IAM role assumed by instances of this fleet.

      Parameters:
      statement - This parameter is required.
    • addUserData

      @Stability(Stable) public void addUserData(@NotNull @NotNull String... commands)
      Add command to the startup script of fleet instances.

      The command must be in the scripting language supported by the fleet's OS (i.e. Linux/Windows). Does nothing for imported ASGs.

      Specified by:
      addUserData in interface IAutoScalingGroup
      Parameters:
      commands - This parameter is required.
    • addWarmPool

      @Stability(Stable) @NotNull public WarmPool addWarmPool(@Nullable WarmPoolOptions options)
      Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.

      Specified by:
      addWarmPool in interface IAutoScalingGroup
      Parameters:
      options -
    • addWarmPool

      @Stability(Stable) @NotNull public WarmPool addWarmPool()
      Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.
      Specified by:
      addWarmPool in interface IAutoScalingGroup
    • applyCloudFormationInit

      @Stability(Stable) public void applyCloudFormationInit(@NotNull CloudFormationInit init, @Nullable ApplyCloudFormationInitOptions options)
      Use a CloudFormation Init configuration at instance startup.

      This does the following:

      • Attaches the CloudFormation Init metadata to the AutoScalingGroup resource.
      • Add commands to the UserData to run cfn-init and cfn-signal.
      • Update the instance's CreationPolicy to wait for cfn-init to finish before reporting success.

      Parameters:
      init - This parameter is required.
      options -
    • applyCloudFormationInit

      @Stability(Stable) public void applyCloudFormationInit(@NotNull CloudFormationInit init)
      Use a CloudFormation Init configuration at instance startup.

      This does the following:

      • Attaches the CloudFormation Init metadata to the AutoScalingGroup resource.
      • Add commands to the UserData to run cfn-init and cfn-signal.
      • Update the instance's CreationPolicy to wait for cfn-init to finish before reporting success.

      Parameters:
      init - This parameter is required.
    • areNewInstancesProtectedFromScaleIn

      @Stability(Stable) @NotNull public Boolean areNewInstancesProtectedFromScaleIn()
      Returns true if newly-launched instances are protected from scale-in.
    • attachToApplicationTargetGroup

      @Stability(Stable) @NotNull public LoadBalancerTargetProps attachToApplicationTargetGroup(@NotNull IApplicationTargetGroup targetGroup)
      Attach to ELBv2 Application Target Group.

      Specified by:
      attachToApplicationTargetGroup in interface IApplicationLoadBalancerTarget
      Parameters:
      targetGroup - This parameter is required.
    • attachToClassicLB

      @Stability(Stable) public void attachToClassicLB(@NotNull LoadBalancer loadBalancer)
      Attach to a classic load balancer.

      Specified by:
      attachToClassicLB in interface ILoadBalancerTarget
      Parameters:
      loadBalancer - This parameter is required.
    • attachToNetworkTargetGroup

      @Stability(Stable) @NotNull public LoadBalancerTargetProps attachToNetworkTargetGroup(@NotNull INetworkTargetGroup targetGroup)
      Attach to ELBv2 Application Target Group.

      Specified by:
      attachToNetworkTargetGroup in interface INetworkLoadBalancerTarget
      Parameters:
      targetGroup - This parameter is required.
    • protectNewInstancesFromScaleIn

      @Stability(Stable) public void protectNewInstancesFromScaleIn()
      Ensures newly-launched instances are protected from scale-in.
    • scaleOnCpuUtilization

      @Stability(Stable) @NotNull public TargetTrackingScalingPolicy scaleOnCpuUtilization(@NotNull String id, @NotNull CpuUtilizationScalingProps props)
      Scale out or in to achieve a target CPU utilization.

      Specified by:
      scaleOnCpuUtilization in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • scaleOnIncomingBytes

      @Stability(Stable) @NotNull public TargetTrackingScalingPolicy scaleOnIncomingBytes(@NotNull String id, @NotNull NetworkUtilizationScalingProps props)
      Scale out or in to achieve a target network ingress rate.

      Specified by:
      scaleOnIncomingBytes in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • scaleOnMetric

      @Stability(Stable) @NotNull public StepScalingPolicy scaleOnMetric(@NotNull String id, @NotNull BasicStepScalingPolicyProps props)
      Scale out or in, in response to a metric.

      Specified by:
      scaleOnMetric in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • scaleOnOutgoingBytes

      @Stability(Stable) @NotNull public TargetTrackingScalingPolicy scaleOnOutgoingBytes(@NotNull String id, @NotNull NetworkUtilizationScalingProps props)
      Scale out or in to achieve a target network egress rate.

      Specified by:
      scaleOnOutgoingBytes in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • scaleOnRequestCount

      @Stability(Stable) @NotNull public TargetTrackingScalingPolicy scaleOnRequestCount(@NotNull String id, @NotNull RequestCountScalingProps props)
      Scale out or in to achieve a target request handling rate.

      The AutoScalingGroup must have been attached to an Application Load Balancer in order to be able to call this.

      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • scaleOnSchedule

      @Stability(Stable) @NotNull public ScheduledAction scaleOnSchedule(@NotNull String id, @NotNull BasicScheduledActionProps props)
      Scale out or in based on time.

      Specified by:
      scaleOnSchedule in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • scaleToTrackMetric

      @Stability(Stable) @NotNull public TargetTrackingScalingPolicy scaleToTrackMetric(@NotNull String id, @NotNull MetricTargetTrackingProps props)
      Scale out or in in order to keep a metric around a target value.

      Specified by:
      scaleToTrackMetric in interface IAutoScalingGroup
      Parameters:
      id - This parameter is required.
      props - This parameter is required.
    • getAutoScalingGroupArn

      @Stability(Stable) @NotNull public String getAutoScalingGroupArn()
      Arn of the AutoScalingGroup.
      Specified by:
      getAutoScalingGroupArn in interface IAutoScalingGroup
    • getAutoScalingGroupName

      @Stability(Stable) @NotNull public String getAutoScalingGroupName()
      Name of the AutoScalingGroup.
      Specified by:
      getAutoScalingGroupName in interface IAutoScalingGroup
    • getConnections

      @Stability(Stable) @NotNull public Connections getConnections()
      The network connections associated with this resource.
      Specified by:
      getConnections in interface IConnectable
    • getGrantPrincipal

      @Stability(Stable) @NotNull public IPrincipal getGrantPrincipal()
      The principal to grant permissions to.
      Specified by:
      getGrantPrincipal in interface IGrantable
    • getOsType

      @Stability(Stable) @NotNull public OperatingSystemType getOsType()
      The type of OS instances of this fleet are running.
      Specified by:
      getOsType in interface IAutoScalingGroup
    • getRole

      @Stability(Stable) @NotNull public IRole getRole()
      The IAM Role in the instance profile.
    • getUserData

      @Stability(Stable) @NotNull public UserData getUserData()
      The Base64-encoded user data to make available to the launched EC2 instances.
    • getMaxInstanceLifetime

      @Stability(Stable) @Nullable public Duration getMaxInstanceLifetime()
      The maximum amount of time that an instance can be in service.
    • getSpotPrice

      @Stability(Stable) @Nullable public String getSpotPrice()
      The maximum spot price configured for the autoscaling group.

      undefined indicates that this group uses on-demand capacity.

    • getAlbTargetGroup

      @Stability(Stable) @Nullable protected ApplicationTargetGroup getAlbTargetGroup()
    • setAlbTargetGroup

      @Stability(Stable) protected void setAlbTargetGroup(@Nullable ApplicationTargetGroup value)
    • getNewInstancesProtectedFromScaleIn

      @Stability(Stable) @Nullable protected Boolean getNewInstancesProtectedFromScaleIn()
    • setNewInstancesProtectedFromScaleIn

      @Stability(Stable) protected void setNewInstancesProtectedFromScaleIn(@Nullable Boolean value)