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.103.1 (build bef2dea)",
date="2024-10-05T03:43:39.019Z")
@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:
Cluster cluster; AutoScalingGroup asg; ICluster importedCluster = Cluster.fromClusterAttributes(this, "ImportedCluster", ClusterAttributes.builder() .clusterName(cluster.getClusterName()) .clusterSecurityGroupId(cluster.getClusterSecurityGroupId()) .build()); importedCluster.connectAutoScalingGroupCapacity(asg, AutoScalingGroupOptions.builder().build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.IApplicationLoadBalancerTarget
IApplicationLoadBalancerTarget.Jsii$Default, IApplicationLoadBalancerTarget.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.autoscaling.IAutoScalingGroup
IAutoScalingGroup.Jsii$Default, IAutoScalingGroup.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.ec2.IConnectable
IConnectable.Jsii$Default, IConnectable.Jsii$Proxy
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancing.ILoadBalancerTarget
ILoadBalancerTarget.Jsii$Default, ILoadBalancerTarget.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.elasticloadbalancingv2.INetworkLoadBalancerTarget
INetworkLoadBalancerTarget.Jsii$Default, INetworkLoadBalancerTarget.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
-
Constructor Summary
ModifierConstructorDescriptionprotected
AutoScalingGroup
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
AutoScalingGroup
(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.void
addSecurityGroup
(ISecurityGroup securityGroup) Add the security group to all instances via the launch template security groups array.void
addToRolePolicy
(PolicyStatement statement) Adds a statement to the IAM role assumed by instances of this fleet.void
addUserData
(@NotNull 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.void
Use a CloudFormation Init configuration at instance startup.void
Use a CloudFormation Init configuration at instance startup.Returnstrue
if newly-launched instances are protected from scale-in.attachToApplicationTargetGroup
(IApplicationTargetGroup targetGroup) Attach to ELBv2 Application Target Group.void
attachToClassicLB
(LoadBalancer loadBalancer) Attach to a classic load balancer.attachToNetworkTargetGroup
(INetworkTargetGroup targetGroup) Attach to ELBv2 Application Target Group.static IAutoScalingGroup
fromAutoScalingGroupName
(software.constructs.Construct scope, String id, String autoScalingGroupName) protected ApplicationTargetGroup
Arn of the AutoScalingGroup.Name of the AutoScalingGroup.The network connections associated with this resource.The principal to grant permissions to.protected Boolean
The maximum amount of time that an instance can be in service.protected Boolean
The 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.void
Ensures 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 void
protected void
protected void
Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
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, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
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 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:
addUserData
in 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:
addWarmPool
in interfaceIAutoScalingGroup
- Parameters:
options
-
-
addWarmPool
Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.- Specified by:
addWarmPool
in 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-init
andcfn-signal
. - Update the instance's CreationPolicy to wait for
cfn-init
to 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-init
andcfn-signal
. - Update the instance's CreationPolicy to wait for
cfn-init
to finish before reporting success.
- Parameters:
init
- This parameter is required.
-
areNewInstancesProtectedFromScaleIn
Returnstrue
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 interfaceIApplicationLoadBalancerTarget
- Parameters:
targetGroup
- This parameter is required.
-
attachToClassicLB
Attach to a classic load balancer.- Specified by:
attachToClassicLB
in 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:
attachToNetworkTargetGroup
in 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:
scaleOnCpuUtilization
in 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:
scaleOnIncomingBytes
in 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:
scaleOnMetric
in 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:
scaleOnOutgoingBytes
in 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:
scaleOnSchedule
in 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:
scaleToTrackMetric
in interfaceIAutoScalingGroup
- Parameters:
id
- This parameter is required.props
- This parameter is required.
-
getAutoScalingGroupArn
Arn of the AutoScalingGroup.- Specified by:
getAutoScalingGroupArn
in interfaceIAutoScalingGroup
-
getAutoScalingGroupName
Name of the AutoScalingGroup.- Specified by:
getAutoScalingGroupName
in interfaceIAutoScalingGroup
-
getConnections
The network connections associated with this resource.- Specified by:
getConnections
in interfaceIConnectable
-
getGrantPrincipal
The principal to grant permissions to.- Specified by:
getGrantPrincipal
in interfaceIGrantable
-
getOsType
The type of OS instances of this fleet are running.- Specified by:
getOsType
in 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.undefined
indicates that this group uses on-demand capacity. -
getHasCalledScaleOnRequestCount
-
setHasCalledScaleOnRequestCount
-
getAlbTargetGroup
-
setAlbTargetGroup
-
getNewInstancesProtectedFromScaleIn
-
setNewInstancesProtectedFromScaleIn
-