Class AutoScalingGroup
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.autoscaling.AutoScalingGroup
- All Implemented Interfaces:
IResource,IAutoScalingGroup,IConnectable,ILoadBalancerTarget,IApplicationLoadBalancerTarget,INetworkLoadBalancerTarget,IGrantable,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.113.0 (build fc68b25)",
date="2025-10-14T12:28:05.471Z")
@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(MachineImage.latestAmazonLinux2())
.securityGroup(mySecurityGroup)
.build();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IApplicationLoadBalancerTarget
IApplicationLoadBalancerTarget.Jsii$Default, IApplicationLoadBalancerTarget.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.services.autoscaling.IAutoScalingGroup
IAutoScalingGroup.Jsii$Default, IAutoScalingGroup.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.services.ec2.IConnectable
IConnectable.Jsii$Default, IConnectable.Jsii$ProxyNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancing.ILoadBalancerTarget
ILoadBalancerTarget.Jsii$Default, ILoadBalancerTarget.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.INetworkLoadBalancerTarget
INetworkLoadBalancerTarget.Jsii$Default, INetworkLoadBalancerTarget.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAutoScalingGroup(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedAutoScalingGroup(software.amazon.jsii.JsiiObjectRef objRef) AutoScalingGroup(software.constructs.Construct scope, String id, AutoScalingGroupProps props) -
Method Summary
Modifier and TypeMethodDescriptionaddLifecycleHook(String id, BasicLifecycleHookProps props) Send a message to either an SQS queue or SNS topic when instances launch or terminate.voidaddSecurityGroup(ISecurityGroup securityGroup) Add the security group to all instances via the launch template security groups array.voidaddToRolePolicy(PolicyStatement statement) Adds a statement to the IAM role assumed by instances of this fleet.voidaddUserData(String... commands) Add command to the startup script of fleet instances.Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.addWarmPool(WarmPoolOptions options) Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.voidUse a CloudFormation Init configuration at instance startup.voidUse a CloudFormation Init configuration at instance startup.Returnstrueif newly-launched instances are protected from scale-in.attachToApplicationTargetGroup(IApplicationTargetGroup targetGroup) Attach to ELBv2 Application Target Group.voidattachToClassicLB(LoadBalancer loadBalancer) Attach to a classic load balancer.attachToNetworkTargetGroup(INetworkTargetGroup targetGroup) Attach to ELBv2 Application Target Group.static IAutoScalingGroupfromAutoScalingGroupName(software.constructs.Construct scope, String id, String autoScalingGroupName) protected ApplicationTargetGroupArn of the AutoScalingGroup.Name of the AutoScalingGroup.The network connections associated with this resource.The principal to grant permissions to.protected BooleanThe maximum amount of time that an instance can be in service.protected BooleanThe type of OS instances of this fleet are running.getRole()The IAM Role in the instance profile.The maximum spot price configured for the autoscaling group.The Base64-encoded user data to make available to the launched EC2 instances.voidEnsures newly-launched instances are protected from scale-in.Scale out or in to achieve a target CPU utilization.Scale out or in to achieve a target network ingress rate.scaleOnMetric(String id, BasicStepScalingPolicyProps props) Scale out or in, in response to a metric.Scale out or in to achieve a target network egress rate.scaleOnRequestCount(String id, RequestCountScalingProps props) Scale out or in to achieve a target request handling rate.scaleOnSchedule(String id, BasicScheduledActionProps props) Scale out or in based on time.scaleToTrackMetric(String id, MetricTargetTrackingProps props) Scale out or in in order to keep a metric around a target value.protected voidprotected voidprotected voidMethods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStackMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
Uniquely identifies this class.
-
-
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:
addLifecycleHookin interfaceIAutoScalingGroup- Parameters:
id- This parameter is required.props- This parameter is required.
-
addSecurityGroup
Add the security group to all instances via the launch template security groups array.- Parameters:
securityGroup- : The security group to add. This parameter is required.
-
addToRolePolicy
Adds a statement to the IAM role assumed by instances of this fleet.- Parameters:
statement- This parameter is required.
-
addUserData
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:
addUserDatain interfaceIAutoScalingGroup- Parameters:
commands- This parameter is required.
-
addWarmPool
Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.- Specified by:
addWarmPoolin interfaceIAutoScalingGroup- Parameters:
options-
-
addWarmPool
Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.- Specified by:
addWarmPoolin interfaceIAutoScalingGroup
-
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-initandcfn-signal. - Update the instance's CreationPolicy to wait for
cfn-initto finish before reporting success.
- Parameters:
init- This parameter is required.options-
-
applyCloudFormationInit
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-initandcfn-signal. - Update the instance's CreationPolicy to wait for
cfn-initto finish before reporting success.
- Parameters:
init- This parameter is required.
-
areNewInstancesProtectedFromScaleIn
Returnstrueif 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:
attachToApplicationTargetGroupin interfaceIApplicationLoadBalancerTarget- Parameters:
targetGroup- This parameter is required.
-
attachToClassicLB
Attach to a classic load balancer.- Specified by:
attachToClassicLBin interfaceILoadBalancerTarget- Parameters:
loadBalancer- This parameter is required.
-
attachToNetworkTargetGroup
@Stability(Stable) @NotNull public LoadBalancerTargetProps attachToNetworkTargetGroup(@NotNull INetworkTargetGroup targetGroup) Attach to ELBv2 Application Target Group.- Specified by:
attachToNetworkTargetGroupin interfaceINetworkLoadBalancerTarget- 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:
scaleOnCpuUtilizationin interfaceIAutoScalingGroup- 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:
scaleOnIncomingBytesin interfaceIAutoScalingGroup- 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:
scaleOnMetricin interfaceIAutoScalingGroup- 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:
scaleOnOutgoingBytesin interfaceIAutoScalingGroup- 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:
scaleOnSchedulein interfaceIAutoScalingGroup- 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:
scaleToTrackMetricin interfaceIAutoScalingGroup- Parameters:
id- This parameter is required.props- This parameter is required.
-
getAutoScalingGroupArn
Arn of the AutoScalingGroup.- Specified by:
getAutoScalingGroupArnin interfaceIAutoScalingGroup
-
getAutoScalingGroupName
Name of the AutoScalingGroup.- Specified by:
getAutoScalingGroupNamein interfaceIAutoScalingGroup
-
getConnections
The network connections associated with this resource.- Specified by:
getConnectionsin interfaceIConnectable
-
getGrantPrincipal
The principal to grant permissions to.- Specified by:
getGrantPrincipalin interfaceIGrantable
-
getOsType
The type of OS instances of this fleet are running.- Specified by:
getOsTypein interfaceIAutoScalingGroup
-
getRole
The IAM Role in the instance profile. -
getUserData
The Base64-encoded user data to make available to the launched EC2 instances. -
getMaxInstanceLifetime
The maximum amount of time that an instance can be in service. -
getSpotPrice
The maximum spot price configured for the autoscaling group.undefinedindicates that this group uses on-demand capacity. -
getHasCalledScaleOnRequestCount
-
setHasCalledScaleOnRequestCount
-
getAlbTargetGroup
-
setAlbTargetGroup
-
getNewInstancesProtectedFromScaleIn
-
setNewInstancesProtectedFromScaleIn
-