Cleaning Up Resources#

Overview

Teaching: 15 mins

Exercises: 5 mins

Questions:

  • How do I clean up resources on my AWS account to minimize cost?

  • What are the best practices to ensure there is no cost overrun?

Objectives:

  • Learn to clean up AWS resources

Deleting a virtual machine#

We will use the console to delete our virtual machine. Let’s return to the EC2 console. The steps to delete a virtual machine are:

  1. In the navigation pane, choose EC2.

  2. Select the instance, and choose Instance state > Terminate instance.

  3. Choose Terminate when prompted for confirmation.

Exercise

What is the difference between Stopping and Terminating an instance?

Answer

The key difference between stopping and terminating an instance is that the attached bootable EBS volume will not be deleted. The data on your EBS volume will remain after stopping while all information on the local (ephemeral) hard drive will be lost as usual. The volume will continue to persist in its availability zone. Standard charges for EBS volumes will apply.

Deleting an s3 bucket#

You can also use the AWS console to delete the s3 bucket you created earlier, but we will explore how the AWS CLI can be used to achieve it similiarly.

  1. Open the AWS CloudShell

  2. List your s3 buckets

aws s3 ls
  1. Try to remove the bucket by typing this command:

aws s3 rb s3://bucket-userXXXXXXXX

You will receive this error:

remove_bucket failed: s3://user1824906-bucket An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty.

This is because the bucket cannot be deleted if it is not empty. Let’s try deleting the files inside the bucket.

  1. Delete files inside the bucket

aws s3 rm s3://bucket-userXXXXXXXX/*
  1. Delete bucket aws s3 rb s3://bucket-userXXXXXXXX

Finally let’s check that all the resources we have provision throughout the lesson has been deleted. How would you do that?

Exercise

How would you check if your resources have been deleted?

Answer

You can use the AWS Tag Editor to check if your instance and s3 bucket has been deleted. You can also use the EC2 Global View and s3 console to double check.

Additional Steps if using AWS Academy#

  1. Return to your AWS Academy Homepage

  2. Stop Lab