What causes an EC2 instance to stop? - amazon-web-services

I suddenly started having issues connecting to my EC2 instance, and in the AWS console, I noticed the instance status was stopped.
I am not very familiar with AWS EC2, but if I understand correctly, EC2 instances don't stop on their own, so I must have triggered it somehow. How could this happen? Could it have errored out somehow, or did someone have to explicitly stop it?

AWS doesn't take any action by own; there might a possibility you have triggered it by mistake. Since you can start it again also you can set one cloudwatch alarm to get more notification about the running Instance.
At the same time, you can create one topic for SNS and subscribe to it via email. so that if anything happens with your instance it will notify you or you can set the action for all the available events

Related

Always keep EC2 Instance running even if it was stopped based on its TAG

I have some EC2 instances with specific TAGs that are monitored by event bridge and if some action occur the instance must be stopped and then started again. This was already done. But sometimes the instance didn't start again (looks like the event bridge don't get the event of stopped instance to automatically start it).
Which is the best way to schedule a script or something else to every minute check all the stopped instances with specific TAG and then start it?
Thanks in Advance!
In this case I used a Python Lambda function to perform the EC2 start.
And the lambda is scheduled by eventbridge (cloud Watch Events)

Unable to launch EC2 instance even after deleting CloudWatch

I just figured out about AWS CloudWatch that would let you terminate your EC2 instance after some time in inactivity. So I created an alarm that would terminate the instance when the CPU usage is less the 1% for 2 hours. Which ultimately ended up putting my instance into an alarm state right away and it prevented me from starting it up to test the feature out.
I then deleted the CloudWatch alarm again in order to be able to launch the EC2 instance gain but even after I deleted the CloudWatch, the state is set to Terminated but the but the Start option from the Actions drop down button is still disabled.
How do I get the instance to start again?
You can't restart a terminated instance. The instance no longer exists. It is just listed as "terminated" in your web console for a little bit so you can see that it was deleted. You have to create a new instance now.

monitor ec2 instances lifecycle

Hi I am new to AWS and I started learning now. In my environment I noticed all the issues are getting raised by autoscaling only. Whenever new instances comes up there are some small issues happening in environment. So I thought if we have a script to trigger a alert whenever any ec2 instance get reboots or terminates or any new instance spins up but I do not have a idea how to achieve it.
While checking with AWS support they are pointing cloudwatch where we need to trigger alarm for each instance. When we have huge number of instances and multiple environments, setting up a alarm for individual instance is hectic job. Can anyone suggest how can I get information about a instance reboot, termination and new instance spin up. Thanks in advance.
You can create SNS notification whenever auto scaling scales.
Read AWS documentation
You can write your script in your favourite language which can subscribe to the particular SNS topic.

Find the reason for the failure of a EC2 instance

When a amazon EC2 instance goes down (AWS), how to find out the reason for the termination of the instance?
Is it possible to add a notification for the same?
Thanks.
After you launch an instance, you can check its status to confirm that it goes from the pending state to the running state, not the terminated state. If it is terminated you can check the description with ec2-describe-instances instance_id -v as mentioned here : More Info - AWS Docs
If it gets launched correctly and goes to running state, it should not go to terminated state without explicit action on it, You can use terminate protection option when creating the instance to remove the scope of accidental click.
If you want to use send notification, you can create a CloudWatch Event which can trigger a SNS topic:
Create a new CloudWatch event
In Event selector section, select specific and choose Terminated
Select target instance as Any or Specific
Add a target as SNS topic for notification
If the instance is in an auto-scaling group, you can look at the "Activity History" tab to find out broadly, why an instance went down e.g. it was considered unhealthy:
If your instances keep getting terminated, login to the instance before it goes down and watch any relevant logs. Or, even better, if your logs are going to CloudWatch then you can look at the instance logs there.
#Chandan Nayak's answer explains how to configure the SNS messaging.

Using a stop alarm with a g2.2xlarge instance on Amazon's ec2 aws

While working with a g2.2xlarge spot instance, I have tried to set up an alarm that will notify me when the average CPU usage over a two hour period has dropped below 5% and will then automatically stop the instance. Here's a link to a nice article Amazon wrote up on how to use the stop/start instance feature. The AWS alarms seem to allow you to do this however after the trigger goes off I get this reply:
Dear AWS customer,
We are unable to execute the 'Stop' action on Amazon EC2 instance i-e60e21ec that you specified in the Amazon CloudWatch alarm awsec2-i-e60e21ec-Low-CPU-Utilization.
You may want to check the alarm configuration to ensure that it is compatible with your instance configuration. You can also attempt to execute the action manually.
These are some possible reasons for this failure and steps you can try to resolve it:
Incompatible action selected:
Your instance’s configuration may not be compatible with the selected action.
To execute the 'Terminate' action, your instance may have Termination Protection enabled. Disable this feature if you want to terminate your instance. Once you do that, the alarm will execute the action after the next applicable alarm state change.
To execute the 'Stop' action, your instance’s root device type must be an EBS volume. If the root device type is the instance store, select the 'Terminate' action instead. Once you do that, the alarm will execute the action after the next applicable alarm state change.
Temporary service interruption: There may have been an issue with Amazon CloudWatch or Amazon EC2. We have retried the action without success. You can try to execute the action manually, or wait for the next applicable alarm state change.
Sincerely, Amazon Web Services
Stop seems to be an option for the free micro instance but not for these other instances. When I try to change the shutdown behavior to stop in actions it says:
An error occurred while changing the shutdown behavior of this instance.
Modifying 'instanceInitiatedShutdownBehavior is not supported for spot instances.
Is there another way to get around this problem or will we have to wait until Amazon makes this feature available?
Use standard instances instead of spot instances. Spot instances allow you to bid on extra capacity within ec2. However, they may automatically shut down if the spot price exceeds your bid.
Its not really intended for an always on instance.