How to restart ec2 instance from command line

Does your EC2 Instance Reboot or Restart itself? We can help you.

Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.

Today, let us see how the Amazon EC2 instances reboot or restart unexpectedly.

EC2 Instance Reboot or Restart itself

The most common reasons for an unexpected reboot or restart include:

  • The instance fails one or both of its status checks.
  • The underlying hardware hosting the instance is faulty and Amazon EC2 restarts the instance to move it to new, healthy hardware.
  • Scheduled maintenance on the instance that required a reboot.
  • A user or application inside the server rebooted the instance.

Moving ahead, let us see several actions that we can take to determine why the instance reboots.

View status checks

From the console or with the use of AWS Command Line Interface (AWS CLI) we can view the instance’s status checks.

Suppose we receive errors when we run AWS CLI commands. Then we need to make sure that we use the most recent version of the AWS CLI.

View system logs

Suppose the instance didn’t fail a status check, then the instance might have rebooted due to operating system-level issues.

In that case, we review the system logs to determine the error that occurred.

Generally, we can find the system logs at /var/log/messages or /var/log/syslog depending on the OS distribution.

View reboot history

To determine if a user or an application inside the server has initiated the reboot, we use:

# grep reboot /home/*/.bash_history # grep reboot /root/.bash_history # history | grep -i reboot # history | grep -i init # last reboot

View AWS CloudTrail Events history

Instance reboots initiated from the Amazon EC2 console or through the AWS CLI appear in CloudTrail Events history. To view these events:

  1. Initially, we open the AWS CloudTrail console.
  2. Then we select Event history.
  3. Here, we can select the Event name from the filter drop-down and then enter RebootInstances.

[Need help with the fix? We can help you]

Conclusion

In short, we saw how our Support Techs fix the EC2 reboot or restart query.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

I'm trying to stop and then immediately start (NOT REBOOT) my Amazon EC2 server from withinmy instance

I have CLI (Command Line Interface Tools) and am running a Windows 2012 server.

Basically, I want to ec2-stop-instances from a batch, and then ec2-start-instances right after. 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?

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

In previous articles, I have mentioned how to Resize or Upgrade AWS EC2 Instance and What is EC2 (Elastic Compute Cloud) in AWS but now in this article, I have provided step by step procedure to reboot or restart AWS EC2 Instance using AWS Console or using CLI.

There can be situtaion in your EC2 Instance, when you would like to reboot or restart it.

For example, I had some issue on AWS EC2 Instance, I wasn't able to connect to it using RDP until I reboot the system, so in the cases like this we would have to restart or reboot AWS EC2 Instance.

Rebooting an instance is like rebooting a PC, so let's take a look on few way of restarting or rebooting AWS EC2 Instance.

Reboot EC2 Instance using AWS Console

For rebooting AWS EC2 instance using the console, you need to follow below given steps:

  1. Login into your AWS EC2 Console.
  2. Navigate to "Instances" (From left-pane) and Select instance which you want to reboot or restart
  3. Right-click on it and then select "Reboot"
  4. A pop-up will appear, Click 'Yes, Reboot' and confirm.

That's it, now your EC2 will restart in few minutes (1-2 minutes most of the time), during this time-frame, you may not able to access website uploaded on that instance, but if you are using caching using Cloudflare CDN or using Amazon CloudFront content delivery network (CDN), then it show cached pages of website to user.

Restart or reboot AWS Instance using CLI

You can also use Command line Interface tool to reboot or restart AWS instance.

For example, below command will reboot instance, but will not return any success message

aws ec2 reboot-instances --instance-ids i-1234567890abcdef5

Reboot AWS using Powershell

First, we will need AWS key and credentials for this, here are the steps to follow

  1. Go to your account, select Security Credentials and create an AWS access key and secret key.
  2. Open Power-Shell for AWS, which will ask for your AWS Access Key and Secret Key.
  3. If Power-Shell doesn't prompt for keys go to "C:\Users\Administrator\AppData\Local\AWSToolkit" and delete the Registered Account Jsonfile and open Power-Shell again.
  4. Now get your instance id by using this URL from EC2 instance
    //179.254.169.254/latest/meta-data/instance-id // here 179.254.169.254 is my private ip for instance?
  5. Now from powershell give below command
    Restart-EC2Instance -InstanceId i-12345678?

That's it, it will reboot your AWS Instance.

You may also like to read:

How to check the total number of object stored in S3 bucket in AWS?

How can I download complete AWS S3 Bucket Locally?

Create EC2 instance with step by step guide (Windows Server instance)

Error : This configuration section cannot be used at this path. This happens when the section is locked at a parent level?

How do I start and stop an EC2 instance from command line?

To stop and start an Amazon EBS-backed instance using the command line.
stop-instances and start-instances (AWS CLI).
Stop-EC2Instance and Start-EC2Instance (AWS Tools for Windows PowerShell).

Is it safe to reboot an EC2 instance?

We recommend that you use Amazon EC2 to reboot your instance instead of running the operating system reboot command from your instance. If you use Amazon EC2 to reboot your instance, we perform a hard reboot if the instance does not cleanly shut down within four minutes.

How do I start an EC2 instance in putty?

ppk file using PuttyGen..
Load your . pem file generated by AWS. Then save the private key (. ... .
Add user name..
Add your ppk file..
Click on Open. Give the ip address or the host name. Then in data section give the User name for the instance for linux its generally "ec2-user". ... .
Here it is. Now you can access your EC2 instance..

How do I start and stop an EC2 instance using lambda?

To stop and start EC2 instances at regular intervals using Lambda, do the following:.
Create a custom AWS Identity and Access Management (IAM) policy and execution role for your Lambda function..
Create Lambda functions that stop and start your EC2 instances..
Test your Lambda functions..

Related Posts

Toplist

Latest post

TAGs