Fetch autoscaling group name in AWS

amazon-web-servicesaws-cli

Folks,
I am writing a script that will export the tags for a running instance as environment variables.
Problem with autoscaling groups, is that these tags are not available to the instance.

How does one know which autoscaling group an instance belongs to via api/aws cli commands? I need to use instance tags in scripts, however, they are not available. Suggestions?

Thanks!

Best Answer

How does one know which autoscaling group an instance belongs to via api/aws cli commands?

You can use the autoscaling describe-auto-scaling-instances command together with the option --instance-ids, like this:

aws autoscaling describe-auto-scaling-instances --instance-ids="i-zzxxccvv"

Problem with autoscaling groups, is that these tags are not available to the instance. [...] I need to use instance tags in scripts, however, they are not available. Suggestions?

I'm interpreting this as you want to get the tags of the autoscaling group from which the instance belongs to? Using the AutoScalingGroupName returned from the command shown above, you can use the following command:

aws autoscaling describe-tags --filters Name=auto-scaling-group,Values=name-of-the-auto-scaling-group-here
Related Topic