2

When logged onto a AWS EC2 instance say some Ubuntu box and I issue

sudo shutdown now

how is that different from stopping the same instance using

aws ec2 stop-instances --instance-ids  $curr_instanceid --region $AWS_REGION

either way I see the instance gets into the state of stopped and it will transition into state running once this is run

aws ec2 start-instances --instance-ids   $curr_instanceid --region $AWS_REGION

1 Answer 1

1

Just to state the obvious for junior folks who might come across this: sudo shutdown now requires access to the operating system (via SSH keys, inbound security groups, etc), while aws ec2 stop-instances is an AWS CLI command which simply requires API authentication (via IAM credentials or STS tokens).

Aside from the obvious difference in invocation, the shutdown is the same.

When you stop or hibernate an instance, we shut it down. You can restart your instance at any time. Before stopping or hibernating an instance, make sure it is in a state from which it can be restarted. Stopping an instance does not preserve data stored in RAM, but hibernating an instance does preserve data stored in RAM. If an instance cannot hibernate successfully, a normal shutdown occurs.

Source: stop-instances documentation

The --hibernate flag defaults to false, so a normal shutdown is triggered immediately by your CLI command.

When --hibernate is true, the suspend-to-disk process differs from a regular shutdown (such as sudo shutdown now), and is further documented here.

2
  • This answer seems incomplete to me. In stating "the shutdown is the same", are you saying that from the perspective of the OS running in the instance, the two shutdowns behave identically? If you are saying that, then I see nothing here to back up that statement. Shutting down a Linux instance via sudo shutdown now is well understood. What does a shutdown look like from the OS's perspective when the instance is stopped via the AWS CLI? If the two are the same, EC2 must then gain a command prompt as root on the instance and execute a "sudo shutdown now"? Is that what happens?
    – CryptoFool
    Jan 22, 2021 at 7:05
  • ...if the two shutdowns are not actually the same, then this not an answer to the question, as it does not describe how the two operations differ. If the two operations are still nearly identical, then maybe this answer is substantively correct. However, I think that needs to be clearly stated. As it is, this answer provides me with no confidence that I may use the two operations interchangeably and assume no difference in result.
    – CryptoFool
    Jan 22, 2021 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.