Most actions you can do on an instance are synchronous – for instance, if you send a stop request , it will be ran immediately and the program will block until it's completed.
RebootInstanceRequest , however, just schedule a reboot to be done later.
Is there a way to access the schedule of an instance to know a reboot is planned, or in some other way to wait until the reboot is complete?
if you send a stop request, it will be ran immediately and the program will block until it's completed
Not true. When you issue a ec2:StopInstance
request, the instance moves from a running
to stopping
state. But your program does not block. The request returns immediately returning the updated instance state. If you want to determine when the EC2 instance is finally in a stopped
state, then you need to poll the EC2 instance state using ec2:DescribeInstances
.
As for reboot requests, once requested, a reboot happens nearly immediately. As your link mentions, if a Linux instance is not rebooted within 4 minutes, AWS ends up forcing a hard reboot.
Since a reboot happens within the EC2 instance hardware, the state of the EC2 instance does not change from running
. There is no rebooting
state. And there is no mechanism to determine when the OS of your EC2 instance starts and/or completes it's reboot other than monitoring messages in the EC2 instance console log.
Pretty much the best you can do is issue the reboot request and assume/hope that it's rebooted in the next few minutes.
As an alternative, you can stop and restart the instance:
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.