Profile Image

Peter Borghard

System Architect

Leveraging Ec2 tags

When bringing new ec2 instances online I use a basic set of userdata commands to get our servers ready to accept traffic. Not knowing the state of the userdata scripts can be a problem. I came up with a simple way to determine what’s going on, the last step of the userdata script creates an ec2 tag which shows which hosts are completed.

aws ec2 describe-instances --filters "Name=tag:deployEnv,Values=nonprod" "Name=tag:role,Values=webNodes" | jq --raw-output '( .Reservations[].Instances[].Tags[] | select(.Key=="cloud-init-status").Value)'

completed
completed
completed

Maybe cloud-init isn’t your thing, I guess my point here is that the possibilities are endless. Here’s another example of some ec2 instances that are tagged with a version number to verify which code is on the server.

aws ec2 describe-instances --filters "Name=tag:deployEnv,Values=qa" "Name=tag:role,Values=serviceNodes" | jq --raw-output '( .Reservations[].Instances[].Tags[] | select(.Key=="version").Value)'

v237.1
v237.1
v237.1
v237.1
v237.1

Leave a Reply

Your email address will not be published. Required fields are marked *