You can do interesting things with the AWS CLI (Command Line Interface). One of those things is to cause an EC2 instance to self destruct. We will see how to do that here.
- Launch an EC2 Instance.
- Create a new IAM user. Save the secret access keys on your computer, either by cutting / pasting, or downloading the .csv file and opening it in a spreadsheet.
- SSH into the EC2 instance
- Configure the AWS CLI. This is where you paste the Access and Secret Keys that you saved.
Choose the region that you launched the instance in: In the example above, my instance is in Ohio, which is us-east-2. You can find the official region names in the AWS regions and endpoints documentation.
Leave the output format blank to default. Now AWS access is configured. The access credentials are now stored on the EC2 instance.
Where are these credentials stored? Access the .aws hidden folder below to find out.
nano is the text editor for linux. When you type in nano credentials, it’s like opening up a text editor to view the contents of the file. It is in this file that you will see the Access & Secret Keys stored on the instance.
Now it’s time to self destruct this EC2 instance!
Let’s view the instances we have in the region with the describe command.
Look for the Instance ID of the instance that you’re currently using and make a note of it. We will need that when we run the terminate command. Oh and make sure you have the correct ID, because you wouldn’t want to destroy another instance that you wanted to keep!
after typing in the terminate-instances command, you have to paste in the instance id. After doing that, you see the message that the system is going down. Bye Bye Boom! It’s destroyed. Gotta love Cloud Computing.