Reputation: 2119
I'm using node.js and AWS with autoscaling. A javascript SDK solution is preferable but at this point I'll take anything.
I'm hoping this is super easy to do and that I'm just an idiot, but how does one go about getting the public IP addresses of instances that are undergoing the scaling event?
I'm trying to keep a list of active public IP's within a specific application tier so I can circumvent ELB for websocket connections, but I can't figure out how to programmatically get the public IP addresses of the instances that have just been added/removed.
Upvotes: 0
Views: 390
Reputation: 31
For me, and Sensu Client config, I add a basic sensu client config in the base AMI for my instances with "this_hostname" "this_ip" and "this_role." Then I just add some simple sed's in my cloudformation user_data script that curl the aws endpoint for the public ip's as the instance boots. Each cloudformation script sets/exports the APP_TYPE(downcased) in the same user_data script prior to my sed lines, so I reuse that as the role for sensu:
"sed -i \"s/this_hostname/$(curl http://169.254.169.254/latest/meta-data/public-ipv4)/\" /etc/sensu/conf.d/client.json\n",
"sed -i \"s/this_ip/$(hostname -i)/\" /etc/sensu/conf.d/client.json\n",
"sed -i \"s/this_role/${APP_TYPE,,}/\" /etc/sensu/conf.d/client.json\n",
You can also use the internal IP for both, or external for both hostname/IP, to which you can see examples of both above...
For Shutdown, I use a simple /etc/rc0.d/S01Instance_Termination script that is symbolically linked from /etc/init.d/instance_termination that runs a similar curl to remove itself from the host on instance shutdown:
Upvotes: 1