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

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

Related

Adjusting AWS ECS spot request

I have AWS ECS cluster but spot instance type I selected is too small.
I can't find way to adjust Spot Fleet request ID or change Instance type(s) for Spot Fleet request cluster is using.
Do I have to create a new cluster with a new spot fleet request?
Is there any cli option to adjust cluster?
Do I have manually order EC2 with ECS optimized AMI ?
UPDATE In question How to change instance type in AWS ECS cluster? that sounds similar advised to copy Launch Configuration. But I have no Launch Configuration
There is no way of changing the instance types' requested by a spot fleet after its been created.
If you want to run you ECS workload on another instance type, create a new spot fleet (with instances which are aware of your ECS cluster).
When the spot instances spin up, they will register with your ECS Cluster.
Once they are registered, you can find the old instances (in the ECS Instances tab of the cluster view) and click the checkbox net to them.
Then, go to Actions -> Drain instances
This tells ECS that you no longer wish to use these instances. New tasks will now be scheduled on the new instances.
Once all the tasks are running on the new instances, you can delete the old spot fleet.
On the subject of launch configurations. There are two ways of creating collections of spot instances.
Through a Spot Fleet (which is what you're doing)
Through and Auto Scaling Group (ASG)
ASGs allow you to supply a launch configuration (basically a set of instructions to set up an EC2 instances.
Spot Fleets only allow you to customise the instance on creation via User Data.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
Because you're using Spot Fleets, Launch Configurations are really a consideration for you.

An unknown AWS EC2 instance running which recreates even after termination

I am running amazon AWS ECS container which creates one single instance of EC2. I made sure that it is 1 instance when I created ECS.
My issue is that I have another instance running in EC2 and amazon has sent me an email that I am using double of the free quota and will be charged.
But I am not sure why this second EC2 instance is coming from.
I have terminated it many times but it is recreated. When I terminate it, this is the prompt i receive which advises me that it is created from EBS but there is no app in EBS
On an EBS-backed instance, the default action is for the root EBS volume to be deleted when the instance is terminated.
Storage on any local drives will be lost.
This name of the instance is.
ECS Instance - amazon-ecs-cli-setup-ecs-cricketscorer
Please help.
check if you have any Auto Scaling Groups that you do not recognize. It is most probably being created because of it. If not, change your account password and deactivate/delete your existing AccessKeys.

How to change instance type in AWS ECS cluster?

I have a cluster in AWS EC2 Container Service. When I've set it up, I used t2.micro instances because those were sufficient for development. Now I'd like to use more powerful instances, like m4.large.
I would like to know whether it is possible to change the instance types only, so I don't need to recreate the whole cluster. I could not find how to do this.
Yes, you can achieve this in CloudFormation.
Click on the Stack corresponding to your ECS-Cluster.
Click Update Stack
Use radiocurrent template, Next
change EcsInstanceType
Next, Next, Update
Upscale your cluster to 2*n instances
Wait for the n new instances of the new type being created
Downscale your cluster to n
Or you could just drain and terminate the instances 1 by 1
Yes, this is possible.
The instance types in your cluster are determined by the 'Instance Type' setting within your Launch Configuration. To update the instance type without having to recreate the cluster:
Make a copy of the cluster Launch Configuration and update the 'Instance Type'.
Adjust the cluster Auto Scaling Group to point to your new Launch Configuration.
Wait for your new instances to register in your cluster and your services to start.
You can also add multiple instances types to a single cluster by creating multiple Auto Scaling Groups linked to different Launch Configurations. Note however that you can't copy Auto Scaling Groups easily within the console.
To do it without any downtime:
Create a copy of the Launch Configuration used by your Auto Scaling
Group, including any changes you want to make.
Edit the Auto Scaling Group to:
Use the new Launch Configuration
Desired Capacity = Desired Capacity * 2
Min = Desired Capacity
Wait for all new instances to become 'ACTIVE' in the ECS Instances tab of the ECS Cluster
Select the old instances and click Actions -> Drain Instances
Wait until all the old instances are running 0 tasks
Edit the Auto Scaling Group and change Min and Desired back to their original values
Here are the exact steps I took to update the instance type on my cluster:
Go to the cluster service, update Number of tasks to 0
Go to EC2 -> Launch Configurations -> Actions dropdown -> Copy launch configuration and set the new instance type
Go to EC2 -> Auto Scaling Groups -> Edit -> set Launch Configuration to newly created launch configuration
Go to EC2 -> Auto Scaling Groups -> Instances -> Detach instance
Go to EC2 -> Launch Configurations -> Delete old launch configuration
Go to the cluster service, update Number of tasks to your desired count.
Now when tasks start, it'll be running on the updated EC2 instance type.
This can be achieved by modifying EcsInstanceType in the CloudFormation stack for the ECS instance. Any change to the autoscaling group by hand will be overwritten by the next "Scale ECS Instances" operation.
Yes, you can change the instance type in ECS cluster. I believe you have created ECS cluster manually from AWS GUI. Behind the scene, its creating aws cloud formation template as per your inputs from AWS console(ECS) like VPC, instance type, and size, etc. Please follow the below steps for the same.
Find the cloud formation template with the name "EC2ContainerService-{your-ecs-cluster-name}".
Check the existing setting in the Parameters tab(you can check your instance type here).
Now you need to update the cloud formation. Click on-> Update ->use current template ->next->update the EcsInstanceType variable ->next->next->update stack.
Now your cloud formation update. now you can check in EC2 console that there is a new spot fleet with new instance type.
Definitely, there are multiple ways to change the instance type as suggested about using launch configurations.
But beware that, it is a challenge to use multiple launch configuration to attach to ECS cluster that has Container Instances Scaling policies.
For example, If one is running a cluster with t2.medium type of instances using a launch configuration and have a Auto scaling policy attached to ECS cluster then it can signal only Auto scaling group and not more than 1.
The AWS docs has a complete step by step guide covering CloudFormationStack and ECS cluster launched manually.
How do I change my container instance type in Amazon ECS?
From the guide:
To change your container instance type, complete the steps in one of
the following sections:
Update container instances launched in an ECS cluster through the AWS CloudFormation stack
Update container instances launched manually in an ECS cluster

Amazon ECS How to login to the EC2 service it is associated?

After I initiated an Amazon ECS following their tutorial (But I don't recall there is one step that asks me for the key-pair information.)
After I set it up, I found that there is an extra EC2 in my EC2 instance list that starts to charge me money. I wonder what that EC2 is doing.
Is it the EC2 that is associated with ECS that I can start to build my own server on?
If so, how can I log into it? (There is no key-pair information for me to log in. It says I need to log in via valid username-password pair, but I don't even know my username.)
If not, how can I kill it? (Directly terminating it in EC2 service is not helping since it seems ECS will just start another one)
The username will be ec2-user. ECS creates a launch configuration in which you can set key pair
ECS creates an autoscaling group you can find it under ec2/autoscaling/home you can edit this group and set min and desired to 0 this will shut down the instance automatically.

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.