Need to terminate the instance that is in standby. How can it be done.
I terminated instance using instance_id, instance got terminated but still showing in console as standby node.
How can I terminate node and and move from standby without receiving any requests.
I had the same issue. After terminating the instance, go to auto scaling group -> select that instance -> Actions -> Set to InService.
It gets removed automatically from the list.
It is not prefer way to terminate instance while it is on stand by mode in Auto Scaling group. If you manually terminate instance which is in stand by mode, it will still show in auto scaling group. If you want to terminate it, You must place instance in service. After that you can de-attach instance and terminate or stop it as required.
You can also remove the instance while it is in standby using the autoscaling CLI/API action 'terminate-instance-in-auto-scaling-group' as per the options below.
$ aws autoscaling terminate-instance-in-auto-scaling-group
--instance-id <value>
--should-decrement-desired-capacity | --no-should-decrement-desired-capacity
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
Docs: https://docs.aws.amazon.com/cli/latest/reference/autoscaling/terminate-instance-in-auto-scaling-group.html
Related
My EC2 ubuntu instance( id: xxx) got terminated due to EC2 instance status checks failure and launched itself as an new instance (yyy). I wanted to see know the reason behind the termination here. I attempted to have a look CloudTrail -> Event History -> Event Name (Lookup Attributes) -> TerminateInstances. But that didn't help me find a reason for this termination. I also tried using CLI aws ec2 describe-instances --instance-id xxx, but what I got is empty array
{ "Reservations": [] }
Any help in finding a way to get the logs would be great.
For a AWS EC2 Instance, Is it possible to unassign or remove a security group from a instance using the cmd line. It is easy to do via the UI, but I can't seem to do it easily via the API. I am restricted to using AWS cli version 1 for now. https://docs.aws.amazon.com/cli/latest/reference/ec2/index.html
I have looked at using the modify instance attribute but it seems like a really round about way to unassign a security group from a instance. I have to reassign all other groups except for the security group I do not want assigned
aws ec2 modify-instance-attribute --instance-id [Instance ID] --groups [groups]
Deleting the security group, will not work as it is assigned to a instance.
aws ec2 delete-security-group --group-id [grou id]
I get the correct error
<br>
An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation
Is there a easier way to remove or unassign a security group from a instance other than using the modify-instance-attribute using the cmd line?
I've hit a dead-end on my debugging and I'd appreciate any insight y'all could provide.
I setup an auto scaling group (ASG) of size 1 using launch templates in a public subnet. The ASG is configured with a creation policy and an update policy. The instance user data invokes cfn-signal after cfn-init has completed.
During my initial deployment, CloudFormation pauses for the signals, but ultimately times out and a rollback occurs. I set a pause time of 10 minutes in the creation policy, which should be more than enough time. To debug, I deploy again, ssh into the instance during the pause after the EC2 instance checks have passed, I check the logs with
sudo grep -ni 'error\|failure' $(sudo find /var/log -name cfn\* -or -name cloud-init\*)
, and I find no errors. cfn-init.log shows cfn-signal transmitting a SUCCESS status, and cfn-wire.log shows the associated HTTP response with a 200 status. I then attempt to manually send the signal, and stdout shows the following, indicating that signal has already been sent:
[DEBUG] Signaling resource <ASG_LOGICAL_ID> in stack <STACK_NAME> with unique ID <INSTANCE_ID> and status SUCCESS
ValidationError: Signal with ID <INSTANCE_ID> for resource <ASG_LOGICAL_ID> already exists. Signals may only be updated with a FAILURE status.
CloudFormation stack event logs on AWS management console shows that the ASG is still in CREATE_IN_PROGRESS. The transmission of the success signal is not causing the transition to CREATE_COMPLETE.
To test the update policy, I commented out the creation policy, deployed, changed the key pair name in the launch template to another one that also works so I could trigger the update policy, and deployed again. Instance in ASG gets brought down (minimum instance in service is 0 in auto scaling rolling update policy), and its replacement gets brought up. At this point, CloudFormation pauses and waits for signal, and I repeat my debugging steps above only to encounter the same results as above.
Here are more details that may be of use:
Creation Policy was configured like so:
"CreationPolicy" : {
"AutoScalingCreationPolicy" : {
"MinSuccessfulInstancesPercent" : 100,
},
"ResourceSignal" : {
"Count" : 1,
"Timeout" : "PT10M"
}
}
Instance role has a principal policy with the following actions allowed:
cloudformation:DescribeStackResource
cloudformation:SignalResource
The instance is configured to be a NAT instance and it does work. I tested it as suggested here: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html#nat-test-configuration
Logical ID of ASG is passed to resource option of cfn-signal
Logical ID of launch template is passed to resource option of cfn-init
Amazon Linux 2 AMI
Made sure to install aws-cfn-bootstrap
In the launch template, I specified an external network interface to be used as the default network interface of the sole instance. Here's details about that: https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-template.html#change-network-interface
I want to create an ASG with only 1 instance initially.
I want all the instances of this ASG to be behind an ELB.
So I set load_balancers = ["${aws_elb.Production-Web-ELB.name}"] in the resource "aws_autoscaling_group" "ProductionWeb-ScalingGroup" .
Now, when I write the code for the resource "aws_elb" "Production-Web-ELB", and I set instances = ["${aws_autoscaling_group.ProductionWeb-ScalingGroup.*.id}"], I get the error...
Error configuring: 1 error(s) occurred:
* Cycle: aws_autoscaling_group.ProductionWeb-ScalingGroup, aws_elb.Production-Web-ELB
I understand that this error means that the one resource references the other in a circle. To check it I comment out the load_balancers = ["${aws_elb.Production-Web-ELB.name}"] part and terraform plan without any error.
So my question is: Am I unable using Terraform to create an ASG with an attached ELB and every EC2 that will spawn inside it will be automatically behind the ELB ?
Is there something from the documentation that I missed?
Is there a workaround?
You don't need to explicitly define the instances that will be associated with the ELB in terraform's ELB definition. By using the load_balancers argument, you're associating the ELB with the AutoScaling group, and AutoScaling will know to attach any instances that are created to that ELB when the AutoScaling group launches that instance.
Terraform isn't directly managing the state of the instances in this case -- AWS AutoScaling is, so their state likewise don't need to be defined in terraform beyond defining a launch configuration and associating it to the AutoScaling group.
To tell terraform to launch the AutoScaling group with a single instance, set your min_size argument to 1 and let your scaling policies handle the desired capacity from there. You could alternatively set desired_capacity to 1, but be wary of managing that state in terraform because it will set the desired_capacity to 1 every time you apply your plan.
The problem I am trying to solve is how to make my code running within an EC2 instance which is part of a load balanced AWS cluster aware of how many other EC2 instances are withing the same cluster/loadbalancer.
I have the following code which when given the name of a LoadBalancer can tell me how many EC2 instances are associated with that Loadbalancer.
DescribeLoadBalancersResult dlbr = loadBalancingClient.describeLoadBalancers();
List<LoadBalancerDescription> lbds = dlbr.getLoadBalancerDescriptions();
for( LoadBalancerDescription lbd : lbds )
{
if( lbd.getDNSName().equalsIgnoreCase("MyLoadBalancer"))
{
System.out.println(lbd.getDNSName() + " has " + lbd.getInstances().size() + " instances") ;
}
}
which works fine and prints out the loadbalancer name and number of instances is has associated with it.
However I want to see if I can get this info without having to provide the Loadbalancer name. In our setup an EC2 instance will only ever be associated with one Loadbalancer so is there any way to go back the way from EC2 instance to Loadbalancer?
I figure I can go down the route of getting all loadbalancers from All regions, iterating through them until I find the one that contains my EC2 instance but I figured there might be an easier way?
An interesting challenge -- I would have to wrangle with the code myself to think this through, but my gut first response would be to use the AWS CLI here, and to just invoke it from within your Java/C#.
You can make this call:
aws elb describe-load-balancers
And get all manner of information about any and all ELBs, and could simply --query filter that by the instance ID of the instance making the call anyway -- in order to find out what other friends the instance has joined to its same ELB. Just call the internal instance metadata to get that ID:
http://169.254.169.254/latest/meta-data/instance-id
Or another fun way to go would be to bootstrap your instance AMIs so that when they are spawned and joined to an ELB, they register themselves in a SimpleDB or DynamoDB table. We do this all the time as a way of keeping current inventories of websites, or software installed, etc. So this way you would have a list, which you could then keep trimmed by checking for "running" status.
EDIT - 4/13/2015
#MayoMan I have hadto make use of this as well in some current work -- to identify healthy instances attached to an ELB in an auto-scaling group and then act upon them. I've found 'jq' to be a really helpful command-line tool. You could also make these calls directly to an ELB, but here it's describing an ASG:
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <ASG Name> | jq -r .AutoScalingGroups[0].Instances[0].HealthStatus
Or to list the InstanceIds themselves:
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <ASG Name> | jq -r .AutoScalingGroups[0].Instances[0-3].InstanceId