Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to find out if a EC2 instance is associated with Auto scaling group

Is there a way to find out if an EC2 instance is associated with Auto Scaling Group?

like image 514
kumar Avatar asked Jan 01 '23 00:01

kumar


1 Answers

You can use the describe-auto-scaling-instances function to check which autoscaling group the instance is attached to.

So for example for instance id i-4ba0837f you could run the following command

aws autoscaling describe-auto-scaling-instances --instance-ids i-4ba0837f

Example response if attached to an autoscaling group is below

{
    "AutoScalingInstances": [
        {
            "ProtectedFromScaleIn": false,
            "AvailabilityZone": "us-west-2c",
            "InstanceId": "i-4ba0837f",
            "AutoScalingGroupName": "my-auto-scaling-group",
            "HealthStatus": "HEALTHY",
            "LifecycleState": "InService",
            "LaunchConfigurationName": "my-launch-config"
        }
    ]
}

However if it is not attached to any this will be an empty list.

{
    "AutoScalingInstances": []
}

If this returns no results then that instance is not part of an autoscaling group.

This will also be available in the SDKs:

  • Boto3
  • NodeJS
  • Java
  • C#
  • PHP
like image 76
Chris Williams Avatar answered Jan 02 '23 14:01

Chris Williams