大网数据广告活动
服务器运维问答

Automatically start an AWS EC2 instance from network request (wake-on-LAN)

· 52CE 我爱测

I'd like to start an EC2 instance on-demand, and to take it down when it is idle for some period of time (e.g. no network activity for >= 1 hour), but I can't tell what a standard way of doing this in AWS looks like, given that A…

问题原文

原帖链接 · koschei · CC BY-SA 3.0

I'd like to start an EC2 instance on-demand, and to take it down when it is idle for some period of time (e.g. no network activity for >= 1 hour), but I can't tell what a standard way of doing this in AWS looks like, given that AWS doesn't support wake-on-LAN.

The service I intend to run will require a persistent network connection, e.g. ssh.

The user experience I am aiming for goes something like this:

  • If the service is up when the user attempts to connect, the user has immediate access to the service.
  • If the service is down when the user attempts to connect, the user receives a "service is starting" reply (and the connection is closed). The user retries after a few minutes and connects successfully (or receives the "starting" message again if he retries too early). The service remains up for up to an hour after the last user disconnects.

My motivation here is primarily cost savings. The demand will be highly unpredictable (so scheduled instances are not a good fit), probably less than 12 active hours/day, and the users are willing to wait a few minutes for the service to start. And I don't want to get locked in to a 1+ year term with reserved instance pricing.

I also have some wild stabs at how I might accomplish this, and would appreciate feedback on how plausible/sensible they are:

  1. Use an auto-scaling group that "scales" the service from 0 to a maximum of 1 instances. But I don't know how I'd be able to issue the "service is starting" reply if there are no instances running.
  2. Run a t2.micro instance when the service is down whose sole purpose is to catch a connection attempt, issue the "starting" reply, trigger the start the actual service instance, and then die. When the service instance goes down due to inactivity, it would need to start the t2.micro instance again.

Thanks!

已采纳解答

原帖链接 · Jason Martin · CC BY-SA 3.0

Lambda works somewhat like this, though instead it makes the user wait while it spins up an app. In Lambda though you don't have an instance to manage -- its all done under the hood.

I'd also check if you could do something involving Lambda and a Route53 failover check, such that users hit Lambda if the instance is down and the instance if it is up. This might not work of Lambda requires a specific Host header though.

Or use R53 failover again to run a reserved-instance t2.nano to do the 'waiting room', then proxy or redirect to another instance once it is up.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。