简体   繁体   English

停止然后从命令行启动EC2

[英]Stopping then starting EC2 from command line

I'm trying to stop and then immediately start ( NOT REBOOT ) my Amazon EC2 server from within my instance 我试图停下来,然后马上从我的实例启动( 不重新启动 )我的亚马逊EC2服务器

I have CLI (Command Line Interface Tools) and am running a Windows 2012 server. 我具有CLI(命令行界面工具),并且正在运行Windows 2012服务器。

Basically, I want to ec2-stop-instances from a batch, and then ec2-start-instances right after. 基本上,我想从批处理中先执行ec2-stop-instances ,然后再执行ec2-start-instances But I want the start-instances to run after a minute or so. 但是我希望启动实例在大约一分钟后运行。

Is there a way to send the command and ask Amazon to wait a minute before it is run? 是否可以发送命令并要求Amazon等待一分钟,然后再运行它?

This way, running the batch script will stop then start the instance. 这样,运行批处理脚本将停止,然后启动实例。

Again, I can't use reboot. 同样,我不能使用重新启动。 For some reason, it does not work with my needs. 由于某种原因,它不能满足我的需求。

I understand this post is 3 years old, but it is possible to do this now with the AWS CLI, https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html 我了解这篇文章已有3年历史了,但是现在可以通过AWS CLI https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html来完成

aws ec2 stop-instances --instance-ids AWS EC2停止实例--instance-ids

aws ec2 start-instances --instance-ids aws ec2 start-instances --instance-ids

This could also be done from a Lambda Function, and scheduled 这也可以通过Lambda函数完成并安排

So what you need to do is to schedule running a command with AWS API 因此,您需要安排使用AWS API运行命令

And it's currently not possible to do it so because AWS API lack this feature. 由于AWS API缺少此功能,因此目前无法这样做。

So you cannot achieve what you described without another EC2 instance/other server/service, to scheduling running the command with something cron -like. 因此,如果没有其他EC2实例/其他服务器/服务,就无法实现您所描述的计划,以计划类似cron运行命令。

(But perhaps it will be possible soon - see this answer for info about it.) (但也许很快就会有可能-有关信息,请参见此答案 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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