1

i have an autoscaling group in AWS.

i want/need to be able to "number" those instances. i'll explain: lets say the ASG raise 5 instances. i want to be able to name those instance as follows: instance-name-0 instance-name-1 ... instance-name-4

is there any way to keep such numbering on the instances? (including when increasing/decreasing the desired count of the instances?)

and extra question of the same nature: how can i do that with a Spot Fleet? (give numbers to the instances, that will hold even after changes in the instances - including spot termination and change in scale)

i kinda believe that there is no such easy way to do what i want, or even hard way - without possible bugs and/or overhead, but i ask anyway - maybe i'll be surprised :)

thanks!

drizzt13
  • 630
  • 6
  • 15
  • 6
    I would like to suggest you do _not_ do this. It comes back to the old "pets vs animals" arguments. Instances launched from an Auto Scaling group are temporary in nature. They have a unique InstanceId, which should be sufficient for tracking their health, viewing log files, etc. Sequential numbering does not help. Also, Auto Scaling can terminate and launch new instances, so what would you do if instance #2 is terminated -- would the next instance be #2, or #5? And what if #4 out of 4 is terminated -- is the next one #4, or #5? Think again _WHY_ you need such numbering - you probably don't. – John Rotenstein Oct 26 '20 at 21:17
  • 1
    @JohnRotenstein - you mirrored my thoughts on the subject. i'm migrating an old big system from other infrastructure to aws - and the code in that system rely somewhat on the numbering of the instances, so i wanted to check and validate that my thoughts that this idea is BAD were true, and that i should just change the system logic rather than copy it along. your response just confirmed that for me - and for that i thank you – drizzt13 Oct 27 '20 at 21:11
  • I do this because an instance-index is lower-cardinality than an instance-id. My monitoring system operator thanks me for this. https://www.robustperception.io/cardinality-is-key/ - a google search for "high cardinality metrics" will get you to a bunch more detail than that if you like. (It is an acceptable tradeoff to me that my metrics will differ/skew if I change instance-type) – Peter Mounce Mar 27 '23 at 17:35

1 Answers1

1

The simplest way to do this would be to create a EventBridge event rule that will apply whenever an instance is launched or terminated successfully. The event would look something like the below:

{
  "source": [
    "aws.autoscaling"
  ],
  "detail-type": [
    "EC2 Instance Launch Successful",
    "EC2 Instance Terminate Successful"
  ],
  "detail": {
    "AutoScalingGroupName": [
      "YOUR-ASG-NAME-HERE"
    ]
  }
}

By adding a target of a Lambda function whenever this event triggers you would be able to review the instances that exist and then apply the logic as you deem fit.

One thing I will mention about naming each instance is that it generally feeds into the concept of pets vs cattle.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68