Everytime I stop an EC2 instance, another one is created - amazon-web-services

I'm new to AWS, and I tried EC2 instances,
But now I want to stop all the instances, and everytime I stop one, another is created,
Is there a way to stop all EC2 instances forever because I have a $1 bill for this,

This is the behaviour of an autoscaling group. Everytime you stop it, its health check fails which is triggering the behaviour you're seeing.
The instance itself should have a tag of aws:autoscaling:groupName containing the autoscaling group name. Find this autoscaling group within the EC2 console and set the minimum, maximum and desired counts to 0.
If the autoscaling group was created outside of the EC2 console i.e. CloudFormation template or part of an ElasticBeanstalk deployment then you should ensure that you change these settings within their configuration not directly via the console.

Related

When does AWS deregister an EC2 from the auto-scaling group during scale-in?

I am trying to figure out when and how AWS deregisters an EC2 from an auto-scaling group during scale-in. I am especially worried about a case when an EC2 which is about to be terminated will receive an incoming request shortly before being terminated. This would naturally cause processing of the requst to fail. The desired behavior would be for AWS to deregister the about-to-be-terminated instance from the group some configurable time before actually terminating it. I have found no documentation about this specific issue. Am I missing something?
There's no configuration that guarantees that a specific time elapses between deregistering an instance from the group and terminating it.
You can use Elastic Load Balancer health checks to remove instances that are not responding from the load balancer endpoint before they are terminated.
From AWS Documentation https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-termination-policies.html
Default termination policy
The default termination policy applies multiple termination criteria before selecting an instance to terminate. When Amazon EC2 Auto Scaling terminates instances, it first determines which Availability Zones have the most instances, and it finds at least one instance that is not protected from scale in. Within the selected Availability Zone, the following default termination policy behaviour applies:
Determine whether any of the instances eligible for termination use the oldest launch template or launch configuration:
[For Auto Scaling groups that use a launch template]
Determine whether any of the instances use the oldest launch template, unless there are instances that use a launch configuration. Amazon EC2 Auto Scaling terminates instances that use a launch configuration before it terminates instances that use a launch template.
[For Auto Scaling groups that use a launch configuration]
Determine whether any of the instances use the oldest launch configuration.
After applying the preceding criteria, if there are multiple unprotected instances to terminate, determine which instances are closest to the next billing hour. If there are multiple unprotected instances closest to the next billing hour, terminate one of these instances at random.

How to terminate AWS managed blockchain instance

I followed these instructions below to get an AWS Ethereum instance running, however since I am just learning blockchain, I would like to create an image and start/stop as needed. However when I go to EC2 and stop my instance, it restarts. I saw other posts about this being caused by elastic beanstalk but when I go to elastic beanstalk, I don't see anything there. What else could be causing it to restart?
Thanks!
https://docs.aws.amazon.com/blockchain-templates/latest/developerguide/blockchain-templates-getting-started.html
If you check the source code of one of its nested stacks ethereum-autoscalegroup.template.yaml, you can see that it actually creates instances in an autoscaling group (ASG).
Instances in ASG can't be stopped. However, you can terminate them, by setting desired capacity and minimum capacity to 0 of your ASG. Then if you want to create new instances when you need them, you can change desired capacity back to 1.

Auto-created EC2 instance and how to delete(terminate) it?

I'm launching an EC2 instance in AWS. And there is an auto-created EC2 instance, named Test-env. Every time I terminated it, AWS would auto-created a new one for me. is there any way to terminate the auto-created instance and prevent it from creating a new one?
Shown in the picture above, I terminated the Test-env twice, and AWS just created a new Test-env for me.
Thank a lot.
It seems like you have been using Elastic Beanstalk. If you open up that section of the AWS Management Console, you can delete the application/environment from there. This will bring down the instance as well. When you terminate the Elastic Beanstalk instance manually through the EC2 section, the system thinks that it has failed and will launch a replacement.
Reference: https://forums.aws.amazon.com/thread.jspa?threadID=115913
It seems that AutoScaling group configuration is present for the EC2 instance Test-env.
Can you please check under EC2 -> AutoScaling Groups -> Test-env -> Scaling Policies?
It seems that ScaleUp Policy has been configured for that instance. It means that whenever total number of EC2 instances are less than or equal to 0 (or any limit which was set) then spawn new one.
You need to update these policies or remove it as per your need.
Other than Elastic Beanstalk and AutoScaling group,
another possibility is you have
an on-going Spot Request.
You can cancel it in order to prevent the instance from recreating.
EC2 -> Instances -> Spot Requests
Then, Actions -> Cancel Request

AWS - EC2 stop instances not working properly

I'm very new on AWS and now I have two EC2 instances. In order to avoid waste the free tier plan I'm trying to stop instances when I'm not working with them.
This is what my EC2 Management console shows. As you can see there are two instances running and two instances terminated. I did not terminate swipe-dev, I have just stop it. But for any reason now is terminated plus new same instance with same source code was started. Why?
What I'm doing wrong? I just want stop instances.
Edit
I have decide keep just one project so I terminate eb-flask-demo-dev and stop swipe-dev instance. After few minutes instace state was stoped and I thought finally everything is fine. But I rejoin to EC2 console and this is what it shows.
Why swipe-dev is running again? and Why there is another terminated instance?
This is possible if your instance is a member of an Autoscaling group with desired capacity = 1 and set minimum size to 0. To maintain the number of healthy instances, Auto Scaling performs a periodic health check on running instances within an Auto Scaling group. When it finds that an instance is unhealthy (in this case because you stopped it), it terminates that instance and launches a new one.

AWS Automatically Generating New Instance After I Terminate It.

OK, odd thing is happening on AWS.
I downloaded the AWS .NET developer tools and created an elastic beanstalk default instance.
I then, for one reason or another, created another instance via the Visual Studio interface and that instance is where all the clients code / configurations reside. I then returned to the default instance created by elastic beanstalk and terminated it. An hour later, I logged back on and another default instance was up and running. It seems that AWS has detected that I terminated the instance and has spawned another. Some sort of check seems to be in place.
Can somebody tell me what is going on here and how to completely remove the default instance (and its termination protection behavior)?
Thanks.
I've experienced something similar. If the instance was created through Elastic Beanstalk, you need to go the Elastic Beanstalk screen in the AWS console and remove the application from there first. If you just terminate the instance from the EC2 screen, Elastic Beanstalk probably thinks that the instance crashed and launches a new one.
if beanstalk is not enable, then most probably it is creating from auto scaling. which is present in EC2 service itself.
Go to auto scaling and first delete the auto configuration group and launch configuration for that associate instance.
As described here it is caused by Auto Scaling Group's desired/minimum 1 instance setting. So, what that means is that the instances in that auto scaling group will always have a running instance. If you delete the only one it will create another one. To prevent this go to EC2 dashboard and on the left sidebar scroll down to find/click Auto Scaling Groups under AUTO SCALING menu. You will see the list of groups where you can click on them to see which instances are in those groups. Find the group that your instance is in and either delete it (that happens when an environment is deleted as well) or change its desired and minimum 1 instance rule to 0 and save. That is it.
Check your autoscaling groups. If you would have created node groups for your EKS cluster.