<p>Example in AWS cli that should work to get the ASG name</p>

<pre><code>a=curl 'http://169.254.169.254/latest/meta-data/instance-id'; aws autoscaling describe-auto-scaling-instances --instance-ids $a --query 'AutoScalingInstances[*].AutoScalingGroupName'
</code></pre>

CC BY-SA 3.0
2017-11-01T09:24:26.993Z
Provided this is sent from the same instance as the service is running at. What about an external script that needs to figure out this information?
Evgeny Zislis
CC BY-SA 3.0
2017-10-31T13:21:17.900Z
2017-10-31T13:21:17.900Z
Vorsprung
<p>Here I ran for ap-south-1 region-</p>

<p>a=<code>curl 'http://169.254.169.254/latest/meta-data/instance-id'c ; 
  aws autoscaling describe-auto-scaling-instances --instance-ids $a --query 'AutoScalingInstances[0].AutoScalingGroupName' --region ap-south-1</code></p>

CC BY-SA 4.0
2020-03-02T12:16:58.230Z
2020-03-02T16:51:32.613Z
2020-03-02T16:51:32.613Z
user19994
<p>We are looking to inspect the ASG EC2 CloudWatch metrics such as CPU and Memory, since it includes an aggregate of all the ASG instances.</p>

<p>Given that we know the ECS cluster, or the ECS service name. Which API calls would be needed to figure out the name of the Auto Scaling Group and its CloudWatch metrics?</p>

CC BY-SA 3.0
2017-07-03T08:31:53.907Z
Isn't the ASG tagged with the ECS cluster name ? (or it's name derived)
Tensibai
CC BY-SA 3.0
2017-07-03T14:03:49.333Z
Not necessarily, the only thing that actually couples the ASG to ECS is the configuration file for `ecs-agent` located on each instance.
Evgeny Zislis
CC BY-SA 3.0
2017-07-03T14:10:38.563Z
Just done a quick test, but my ASG has a tag  `aws:cloudformation:stack-name` wich is valued with `EC2ContainerService-<my-cluster-name>`. Did I miss a point ?
Tensibai
CC BY-SA 3.0
2017-07-03T14:22:32.873Z
Someone wrote that tag explicitly in your CloudFormation template. A good idea, I'll adopt it. But it's it there by default.
Evgeny Zislis
CC BY-SA 3.0
2017-07-03T14:42:44.237Z
I just followed the AWS console wizard to create a sample cluster to test out of curiosity :)
Tensibai
CC BY-SA 3.0
2017-07-03T14:44:09.740Z
And as far as I can tell, every cloudformation stack get this `aws:cloudformation:stack-name` tag automatically.
Tensibai
<amazon-ec2><amazon-cloudwatch><amazon-ecs>
What is the best way to find the Auto Scaling Group of an ECS cluster?
Evgeny Zislis
# What is the best way to find the Auto Scaling Group of an ECS cluster?

(Asked by: username_0 on 2017-07-02)

We are looking to inspect the ASG EC2 CloudWatch metrics such as CPU and Memory, since it includes an aggregate of all the ASG instances.

Given that we know the ECS cluster, or the ECS service name. Which API calls would be needed to figure out the name of the Auto Scaling Group and its CloudWatch metrics?

**Tags:** amazon-ec2, amazon-cloudwatch, amazon-ecs

> **Comments:**
> **username_1**: Isn't the ASG tagged with the ECS cluster name ? (or it's name derived)  
> **username_0**: Not necessarily, the only thing that actually couples the ASG to ECS is the configuration file for `ecs-agent` located on each instance.  
> **username_1**: Just done a quick test, but my ASG has a tag  `aws:cloudformation:stack-name` wich is valued with `EC2ContainerService-<my-cluster-name>`. Did I miss a point ?  
> **username_0**: Someone wrote that tag explicitly in your CloudFormation template. A good idea, I'll adopt it. But it's it there by default.  
> **username_1**: I just followed the AWS console wizard to create a sample cluster to test out of curiosity :)  
> **username_1**: And as far as I can tell, every cloudformation stack get this `aws:cloudformation:stack-name` tag automatically.  

---

## 2 answers

### Answer by username_2 on 2017-10-31. Score: 2

Example in AWS cli that should work to get the ASG name
a=curl 'http://169.254.169.254/latest/meta-data/instance-id'; aws autoscaling describe-auto-scaling-instances --instance-ids $a --query 'AutoScalingInstances[*].AutoScalingGroupName'

> **Comments:**
> **username_0**: Provided this is sent from the same instance as the service is running at. What about an external script that needs to figure out this information?  

---

### Answer by username_3 on 2020-03-02. Score: 0

Here I ran for ap-south-1 region-

a=`curl 'http://169.254.169.254/latest/meta-data/instance-id'c ;
aws autoscaling describe-auto-scaling-instances --instance-ids $a --query 'AutoScalingInstances[0].AutoScalingGroupName' --region ap-south-1`


---

