douglaslps
douglaslps

Reputation: 8168

How to change new instance tag Name when auto scaling

I've created a new Alarm on my AWS account based on a Metric that I also have created. I use this alarm to auto scale. When launching new instances I'm using User Data field to set up this new instance. The only problem I'm facing is that I cannot modify the tags (specially the tag Name) of this new instance. If I don't change that, all the new instances will have the same name which won't work with my current setup.

Is it possible to solve that?

Upvotes: 2

Views: 3420

Answers (1)

Julio Faerman
Julio Faerman

Reputation: 13501

You can set up a new Name tag for the instance in its own user data script using AWS cli tools and the instance metadata. It would look like this:

aws ec2 create-tags \
  --resources $(curl -s http://169.254.169.254/latest/meta-data/instance-id) \
  --tag Key=Name,Value=MyNewNiceName \
  --region=us-east-1

See: http://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html

Upvotes: 4

Related Questions