2

This command should work on any EC2. Then if it uses the instance ID, it should discover it.

Vitor Abella
  • 1,213
  • 8
  • 15

2 Answers2

5

This is the AWS CLI command you have to use.

aws ec2 terminate-instances --instance-ids 'curl http://169.254.169.254/latest/meta-data/instance-id'

If you have Termination protection on you can disable it first from the command line and then use above command.

aws ec2-modify-instance-attribute --disable-api-termination false INSTANCEID
Piyush Patil
  • 14,512
  • 6
  • 35
  • 54
1

you can curl the metadata of the instace to get the instanceId of itselff:

aws ec2 terminate-instances --instance-ids `curl http://169.254.169.254/latest/meta-data/instance-id`

PS:
bare in mind that the instance need to have the termination protection off

sebamontini
  • 360
  • 2
  • 10
  • I did the aws configure but I got the error "An error occurred (UnauthorizedOperation) when calling the TerminateInstances operation: You are not authorized to perform this operation." – Vitor Abella Sep 12 '16 at 16:21