简体   繁体   中英

in AWS shutting down / starting all developers EC2 instance at non office working Hours for cost saving ( using Dynamic IP )

Have a small requirement, I have 50 developers, using EC2 instances for their development tasks, they use it to develop word press sites on their local ec2 instance. Currently they EC2 instances are up and running 24/7 and this increasing the cost involved. If I use the EC2CLI to shutdown and start their EC2 instance they will lose their IP (since we are using dynamic IP and don't want to use static IP as it it cost intensive). They map their IP to a domain name (eg: 1.1.1.1 wwwname.examplesite.com ) in the local windows 7 hosts file.

We plan to shut down their EC2 instance in non-working office hours using EC2 CLI and again start it automatically once the Day begins, but once we start it again, the IP will change and how the developer get to know their IP.

Any inputs on this will be highly Appreciated.

There is no "one click way" to do this afaik, since amazon doesnt really want you to save money this way :).

I have programmed a solution for this by using the AWS SDK: Basically it periodically polls AWS for all instances public hostnames. When it finds them, it registers the public hostname to amazon Route 53 (DNS) with a CNAME link to the public domain name (the one you are now using in windows hosts file) of your choice.

It s the principle of dynamic DNS. It s been working fine for several years. Good luck

A lot of the time, it's actually bad practice to rely upon IP Addresses, as they are subject to change like you touched upon in your answer. You should instead rely upon DNS names.

The best solution would be to write a script gets the current public IP on the instance and updates a DNS A record. It would make most sense to do this with Route 53 as it has a nice API.

You'd need to allocate each employee their own DNS name, and each instance would need to know the DNS name relevant to it (eg. hard coded in script, environment variable etc). Then, you could write a script, make it run each time the instance boots up, and have it do the following:

  1. Submit a HTTP request to http://169.254.169.254/latest/meta-data/public-ipv4 (EC2 meta data service, read more here ) to get the current public IP Address of the instance
  2. Update an A record on Route 53 using the ChangeResourceRecordSets API call.

Using AWS Lambda, you could write a script to stop all instances at a particular time thanks to this recent announcement . But this could pose some small problems if your employees were working late, and were interrupted by their instance shutting down. Also, I wouldn't recommend that you then start all these instances back up again at a particular time. It would be a more cost efficient solution to just allow employees to start their instance each day. What if 5 employees are out sick? If they don't come in to work, their instances won't get started :)

I am probably comming in late but if someone else is looking to do it you could script it using python and boto3 . This will allow you to:

  • Start and stop a given (or all) instances
  • Get the IP adress of a given instance

How about writing a VB script on the developer machine . On windows7 desktop boot, their specific machine would boot up and on windows7 desktop shutdown, could call a VB script to shut down the instance. Or is there any other language I could use instead of VB ( would have to learn VB ) . Cannot use python either cant install python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM