1

I am having AWS EC2 instance and I am using it by putty.

I have also downloaded the EC2 command line API to that ec2 instance.

Now i want to terminate EC2 instance within same EC2 instance using EC2 command line API.

How can i terminate EC2 instance ?

Pravin
  • 2,871
  • 5
  • 26
  • 29

1 Answers1

3

I think you are looking for ec2-terminate-instances command part of ec2-api-tools, check out here

PROMPT> ec2-terminate-instances <intance_id>

Answers for the question here How can I kill all my EC2 instances from the command line? can also help you

Community
  • 1
  • 1
Smita
  • 4,634
  • 2
  • 25
  • 32
  • Yes i am looking for terminating instance but in this case, i have to give instance id. I am not looking for this. What i want is, when i am using instance via putty, through same command line i want to terminate the same instance not all other. Like what we do 'init 0' in linux and 'shutdown -s' in windows. – Pravin Apr 07 '13 at 13:23
  • Ok i got you, you should try `sudo halt` after SSHing to your instance.. see if it works – Smita Apr 07 '13 at 15:04
  • If the instance is set to terminate on user shutdown, then all you have to do is shut it down. This is a flag that can be changed between stop and terminate. – datasage Apr 07 '13 at 17:13
  • You can also retrieve the instance_id from within any EC2 instance (specific to the server you are in at any given moment, you can get any info for that box) from the internal instance metadata: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html In your case you could just issue a wget or curl or GET to: http://169.254.169.254/latest/meta-data/instance-id – Neal Magee Aug 01 '13 at 15:32