Class AutoScalingGroup
A Fleet represents a managed set of EC2 instances.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.AutoScaling
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class AutoScalingGroup : Resource, ILoadBalancerTarget, IConnectable, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, IAutoScalingGroup, IResource, IGrantable
Syntax (vb)
Public Class AutoScalingGroup
Inherits Resource
Implements ILoadBalancerTarget, IConnectable, IApplicationLoadBalancerTarget, INetworkLoadBalancerTarget, IAutoScalingGroup, IResource, IGrantable
Remarks
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.
ExampleMetadata: infused
Examples
Cluster cluster;
AutoScalingGroup asg;
var importedCluster = Cluster.FromClusterAttributes(this, "ImportedCluster", new ClusterAttributes {
ClusterName = cluster.ClusterName,
ClusterSecurityGroupId = cluster.ClusterSecurityGroupId
});
importedCluster.ConnectAutoScalingGroupCapacity(asg, new AutoScalingGroupOptions { });
Synopsis
Constructors
AutoScalingGroup(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
AutoScalingGroup(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
AutoScalingGroup(Construct, String, IAutoScalingGroupProps) |
Properties
AlbTargetGroup | |
AutoScalingGroupArn | Arn of the AutoScalingGroup. |
AutoScalingGroupName | Name of the AutoScalingGroup. |
Connections | The network connections associated with this resource. |
GrantPrincipal | The principal to grant permissions to. |
HasCalledScaleOnRequestCount | |
MaxInstanceLifetime | The maximum amount of time that an instance can be in service. |
NewInstancesProtectedFromScaleIn | |
OsType | The type of OS instances of this fleet are running. |
Role | The IAM Role in the instance profile. |
SpotPrice | The maximum spot price configured for the autoscaling group. |
UserData | The Base64-encoded user data to make available to the launched EC2 instances. |
Methods
AddLifecycleHook(String, IBasicLifecycleHookProps) | Send a message to either an SQS queue or SNS topic when instances launch or terminate. |
AddSecurityGroup(ISecurityGroup) | Add the security group to all instances via the launch template security groups array. |
AddToRolePolicy(PolicyStatement) | Adds a statement to the IAM role assumed by instances of this fleet. |
AddUserData(String[]) | Add command to the startup script of fleet instances. |
AddWarmPool(IWarmPoolOptions) | Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group. |
ApplyCloudFormationInit(CloudFormationInit, IApplyCloudFormationInitOptions) | Use a CloudFormation Init configuration at instance startup. |
AreNewInstancesProtectedFromScaleIn() | Returns |
AttachToApplicationTargetGroup(IApplicationTargetGroup) | Attach to ELBv2 Application Target Group. |
AttachToClassicLB(LoadBalancer) | Attach to a classic load balancer. |
AttachToNetworkTargetGroup(INetworkTargetGroup) | Attach to ELBv2 Application Target Group. |
FromAutoScalingGroupName(Construct, String, String) | |
ProtectNewInstancesFromScaleIn() | Ensures newly-launched instances are protected from scale-in. |
ScaleOnCpuUtilization(String, ICpuUtilizationScalingProps) | Scale out or in to achieve a target CPU utilization. |
ScaleOnIncomingBytes(String, INetworkUtilizationScalingProps) | Scale out or in to achieve a target network ingress rate. |
ScaleOnMetric(String, IBasicStepScalingPolicyProps) | Scale out or in, in response to a metric. |
ScaleOnOutgoingBytes(String, INetworkUtilizationScalingProps) | Scale out or in to achieve a target network egress rate. |
ScaleOnRequestCount(String, IRequestCountScalingProps) | Scale out or in to achieve a target request handling rate. |
ScaleOnSchedule(String, IBasicScheduledActionProps) | Scale out or in based on time. |
ScaleToTrackMetric(String, IMetricTargetTrackingProps) | Scale out or in in order to keep a metric around a target value. |
Constructors
AutoScalingGroup(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected AutoScalingGroup(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
AutoScalingGroup(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected AutoScalingGroup(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
AutoScalingGroup(Construct, String, IAutoScalingGroupProps)
public AutoScalingGroup(Construct scope, string id, IAutoScalingGroupProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props IAutoScalingGroupProps
Properties
AlbTargetGroup
protected virtual ApplicationTargetGroup AlbTargetGroup { get; set; }
Property Value
AutoScalingGroupArn
Arn of the AutoScalingGroup.
public virtual string AutoScalingGroupArn { get; }
Property Value
System.String
AutoScalingGroupName
Name of the AutoScalingGroup.
public virtual string AutoScalingGroupName { get; }
Property Value
System.String
Connections
The network connections associated with this resource.
public virtual Connections_ Connections { get; }
Property Value
GrantPrincipal
The principal to grant permissions to.
public virtual IPrincipal GrantPrincipal { get; }
Property Value
HasCalledScaleOnRequestCount
protected virtual bool HasCalledScaleOnRequestCount { get; set; }
Property Value
System.Boolean
MaxInstanceLifetime
The maximum amount of time that an instance can be in service.
public virtual Duration MaxInstanceLifetime { get; }
Property Value
NewInstancesProtectedFromScaleIn
protected virtual Nullable<bool> NewInstancesProtectedFromScaleIn { get; set; }
Property Value
System.Nullable<System.Boolean>
OsType
The type of OS instances of this fleet are running.
public virtual OperatingSystemType OsType { get; }
Property Value
Role
The IAM Role in the instance profile.
public virtual IRole Role { get; }
Property Value
Remarks
Throws: an error if a launch template is given
SpotPrice
The maximum spot price configured for the autoscaling group.
public virtual string SpotPrice { get; }
Property Value
System.String
Remarks
undefined
indicates that this group uses on-demand capacity.
UserData
The Base64-encoded user data to make available to the launched EC2 instances.
public virtual UserData UserData { get; }
Property Value
Remarks
Throws: an error if a launch template is given and it does not provide a non-null userData
Methods
AddLifecycleHook(String, IBasicLifecycleHookProps)
Send a message to either an SQS queue or SNS topic when instances launch or terminate.
public virtual LifecycleHook AddLifecycleHook(string id, IBasicLifecycleHookProps props)
Parameters
- id System.String
- props IBasicLifecycleHookProps
Returns
AddSecurityGroup(ISecurityGroup)
Add the security group to all instances via the launch template security groups array.
public virtual void AddSecurityGroup(ISecurityGroup securityGroup)
Parameters
- securityGroup ISecurityGroup
: The security group to add.
AddToRolePolicy(PolicyStatement)
Adds a statement to the IAM role assumed by instances of this fleet.
public virtual void AddToRolePolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
AddUserData(String[])
Add command to the startup script of fleet instances.
public virtual void AddUserData(params string[] commands)
Parameters
- commands System.String[]
Remarks
The command must be in the scripting language supported by the fleet's OS (i.e. Linux/Windows). Does nothing for imported ASGs.
AddWarmPool(IWarmPoolOptions)
Add a pool of pre-initialized EC2 instances that sits alongside an Auto Scaling group.
public virtual WarmPool AddWarmPool(IWarmPoolOptions options = null)
Parameters
- options IWarmPoolOptions
Returns
ApplyCloudFormationInit(CloudFormationInit, IApplyCloudFormationInitOptions)
Use a CloudFormation Init configuration at instance startup.
public virtual void ApplyCloudFormationInit(CloudFormationInit init, IApplyCloudFormationInitOptions options = null)
Parameters
- init CloudFormationInit
- options IApplyCloudFormationInitOptions
Remarks
This does the following:
AreNewInstancesProtectedFromScaleIn()
Returns true
if newly-launched instances are protected from scale-in.
public virtual bool AreNewInstancesProtectedFromScaleIn()
Returns
System.Boolean
AttachToApplicationTargetGroup(IApplicationTargetGroup)
Attach to ELBv2 Application Target Group.
public virtual ILoadBalancerTargetProps AttachToApplicationTargetGroup(IApplicationTargetGroup targetGroup)
Parameters
- targetGroup IApplicationTargetGroup
Returns
AttachToClassicLB(LoadBalancer)
Attach to a classic load balancer.
public virtual void AttachToClassicLB(LoadBalancer loadBalancer)
Parameters
- loadBalancer LoadBalancer
AttachToNetworkTargetGroup(INetworkTargetGroup)
Attach to ELBv2 Application Target Group.
public virtual ILoadBalancerTargetProps AttachToNetworkTargetGroup(INetworkTargetGroup targetGroup)
Parameters
- targetGroup INetworkTargetGroup
Returns
FromAutoScalingGroupName(Construct, String, String)
public static IAutoScalingGroup FromAutoScalingGroupName(Construct scope, string id, string autoScalingGroupName)
Parameters
- scope Constructs.Construct
- id System.String
- autoScalingGroupName System.String
Returns
ProtectNewInstancesFromScaleIn()
Ensures newly-launched instances are protected from scale-in.
public virtual void ProtectNewInstancesFromScaleIn()
ScaleOnCpuUtilization(String, ICpuUtilizationScalingProps)
Scale out or in to achieve a target CPU utilization.
public virtual TargetTrackingScalingPolicy ScaleOnCpuUtilization(string id, ICpuUtilizationScalingProps props)
Parameters
- id System.String
- props ICpuUtilizationScalingProps
Returns
ScaleOnIncomingBytes(String, INetworkUtilizationScalingProps)
Scale out or in to achieve a target network ingress rate.
public virtual TargetTrackingScalingPolicy ScaleOnIncomingBytes(string id, INetworkUtilizationScalingProps props)
Parameters
- id System.String
- props INetworkUtilizationScalingProps
Returns
ScaleOnMetric(String, IBasicStepScalingPolicyProps)
Scale out or in, in response to a metric.
public virtual StepScalingPolicy ScaleOnMetric(string id, IBasicStepScalingPolicyProps props)
Parameters
- id System.String
- props IBasicStepScalingPolicyProps
Returns
ScaleOnOutgoingBytes(String, INetworkUtilizationScalingProps)
Scale out or in to achieve a target network egress rate.
public virtual TargetTrackingScalingPolicy ScaleOnOutgoingBytes(string id, INetworkUtilizationScalingProps props)
Parameters
- id System.String
- props INetworkUtilizationScalingProps
Returns
ScaleOnRequestCount(String, IRequestCountScalingProps)
Scale out or in to achieve a target request handling rate.
public virtual TargetTrackingScalingPolicy ScaleOnRequestCount(string id, IRequestCountScalingProps props)
Parameters
- id System.String
- props IRequestCountScalingProps
Returns
Remarks
The AutoScalingGroup must have been attached to an Application Load Balancer in order to be able to call this.
ScaleOnSchedule(String, IBasicScheduledActionProps)
Scale out or in based on time.
public virtual ScheduledAction ScaleOnSchedule(string id, IBasicScheduledActionProps props)
Parameters
- id System.String
- props IBasicScheduledActionProps
Returns
ScaleToTrackMetric(String, IMetricTargetTrackingProps)
Scale out or in in order to keep a metric around a target value.
public virtual TargetTrackingScalingPolicy ScaleToTrackMetric(string id, IMetricTargetTrackingProps props)
Parameters
- id System.String
- props IMetricTargetTrackingProps
Returns