Attach EC2 instances to your Auto Scaling group - Amazon EC2 Auto Scaling
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Attach EC2 instances to your Auto Scaling group

Amazon EC2 Auto Scaling provides you with the option of attaching one or more EC2 instances to your existing Auto Scaling group. After an instance is attached, it is considered part of the Auto Scaling group.

When you attach instances, consider the following:

  • When you attach instances, the desired capacity of the group increases by the number of instances being attached. If the number of instances being attached plus the desired capacity exceeds the maximum size of the group, the request fails.

  • If you attach an instance to an Auto Scaling group that has an attached load balancer target group or Classic Load Balancer, the instance is registered with the load balancer.

For an instance to be attached, it must meet the following criteria:

  • The instance is in the running state with Amazon EC2.

  • The AMI used to launch the instance must still exist.

  • The instance is not a member of another Auto Scaling group.

  • The instance is launched into one of the Availability Zones defined in your Auto Scaling group.

  • If the Auto Scaling group has an attached load balancer target group or Classic Load Balancer, the instance and the load balancer must both be in the same VPC.

Attach an instance (console)

Use the following procedure to attach an instance to your Auto Scaling group.

To attach an instance to an existing Auto Scaling group

  1. Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/.

  2. (Optional) On the navigation pane, under Auto Scaling, choose Auto Scaling Groups. Select the Auto Scaling group and verify that the maximum size of the Auto Scaling group is large enough that you can add another instance. Otherwise, on the Details tab, increase the maximum capacity.

  3. On the navigation pane, under Instances, choose Instances, and then select an instance.

  4. Choose Actions, Instance settings, Attach to Auto Scaling Group.

  5. On the Attach to Auto Scaling group page, for Auto Scaling Group, select the Auto Scaling group, and then choose Attach.

  6. If the instance doesn't meet the criteria, you get an error message with the details. For example, the instance might not be in the same Availability Zone as the Auto Scaling group. Choose Close and try again with an instance that meets the criteria.

Attach an instance (Amazon CLI)

Use the following procedure to attach an instance to your Auto Scaling group.

The examples use an Auto Scaling group with the following configuration:

  • Auto Scaling group name = my-asg

  • Minimum size = 1

  • Maximum size = 5

  • Desired capacity = 2

To attach an instance to an Auto Scaling group

  1. Describe a specific Auto Scaling group using the following describe-auto-scaling-groups command.

    aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names my-asg

    The following example response shows that the desired capacity is 2 and that the group has two running instances.

    { "AutoScalingGroups": [ { "AutoScalingGroupARN": "arn", "ServiceLinkedRoleARN": "arn", "TargetGroupARNs": [], "SuspendedProcesses": [], "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "Tags": [], "EnabledMetrics": [], "LoadBalancerNames": [], "AutoScalingGroupName": "my-asg", "DefaultCooldown": 300, "MinSize": 1, "Instances": [ { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-05b4f7d5be44822a6", "HealthStatus": "Healthy", "LifecycleState": "Pending" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0c20ac468fa3049e8", "HealthStatus": "Healthy", "LifecycleState": "InService" } ], "MaxSize": 5, "VPCZoneIdentifier": "subnet-c87f2be0", "HealthCheckGracePeriod": 300, "TerminationPolicies": [ "Default" ], "CreatedTime": "2019-03-18T23:30:42.611Z", "AvailabilityZones": [ "us-west-2a" ], "HealthCheckType": "EC2", "NewInstancesProtectedFromScaleIn": false, "DesiredCapacity": 2 } ] }
  2. Attach an instance to the Auto Scaling group using the following attach-instances command.

    aws autoscaling attach-instances --instance-ids i-0787762faf1c28619 --auto-scaling-group-name my-asg
  3. To verify that the instance is attached, use the following describe-auto-scaling-groups command.

    aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names my-asg

    The following example response shows that the desired capacity has increased by 1 instance (to a new capacity of 3), and that there is a new instance, i-0787762faf1c28619.

    { "AutoScalingGroups": [ { "AutoScalingGroupARN": "arn", "ServiceLinkedRoleARN": "arn", "TargetGroupARNs": [], "SuspendedProcesses": [], "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "Tags": [], "EnabledMetrics": [], "LoadBalancerNames": [], "AutoScalingGroupName": "my-asg", "DefaultCooldown": 300, "MinSize": 1, "Instances": [ { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-05b4f7d5be44822a6", "HealthStatus": "Healthy", "LifecycleState": "Pending" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0c20ac468fa3049e8", "HealthStatus": "Healthy", "LifecycleState": "InService" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0787762faf1c28619", "HealthStatus": "Healthy", "LifecycleState": "InService" } ], "MaxSize": 5, "VPCZoneIdentifier": "subnet-c87f2be0", "HealthCheckGracePeriod": 300, "TerminationPolicies": [ "Default" ], "CreatedTime": "2019-03-18T23:30:42.611Z", "AvailabilityZones": [ "us-west-2a" ], "HealthCheckType": "EC2", "NewInstancesProtectedFromScaleIn": false, "DesiredCapacity": 3 } ] }