Yogaya Logo

Deleting Resources and cleaning up AWS Account using Cloud-Nuke

Image of Abhishek Sharma

Abhishek Sharma

November 21, 2022


Cloud-nuke is a tool that can save you a lot of time if you want to clean up your aws resources.

Please before you use cloud-nuke, be very careful as this tool is extremely destructive. You can easily destroy production systems or live client environments with this if you’re careless.

It can help you in the following ways:

I highly recommend you do a --dry-run without taking any action to see all the resources that will be deleted before engaging. It's very important.

Cloud-nuke can wipe out the following:

A full updated list can be seen by running cloud-nuke --help

To start, check your

Check your current os

~$ uname -m

Then go to github.com, choose and run your corresponding version.

https://github.com/gruntwork-io/cloud-nuke/releases

Wget https://github.com/gruntwork-io/cloud-nuke/releases/download/v0.5.1/cloud-nuke_linux_amd64

Rename it to cloud-nuke using mv command so as to run it as cloud-nuke.

**Give executable rightsPP

~$ chmod +x cloud-nuke

Run the version command to check it’s installed properly

~$ ./cloud-nuke -v

For help, run

~$ ./cloud-nuke --help

Run this command to check the resources Nuke can wipe out:

~$ ./cloud-nuke aws --list-resource-types

To nuke entire aws account

~$ ./cloud-nuke aws

To delete resources in a particular region, use--exclude-region value

Example, to delete in us-east-2

~$ ./cloud-nuke aws --region us-east-2

If more than one region, include multiple times

~$ ./cloud-nuke aws --region us-east-1 --region us-west-2 --region eu-central-1

To delete all but exclude a particular region, use --exclude-region value

Example: to delete all resources except us-east-1

~$ ./cloud-nuke aws --exclude-region us-east-1

To nuke a particular resource type, use --resource-type value

Example: to delete only one resource say ec-2

~$ ./cloud-nuke aws --resource-type ec2

To nuke multiple resources use --resource-type value multiple times

Example: to delete only ec-2, s3. rds

~$ ./cloud-nuke aws --resource-type ec2 --resource-type s3 --resource-type rds

To nuke all resources excluding a particular resource, use --exclude-resource-type value

Example: to delete everything excluding only s3

$ ./cloud-nuke aws --region us-west-2 --resource-type-exclude s3

To nuke all resources excluding some particular resources, use --exclude-resource-type value multiple times

Example: to delete everything except RDS, S3 and your snapshots

~$ ./cloud-nuke aws --exclude-resource-type ec2 --exclude-resource-type s3 --exclude-resource-type snap

Multitask:

./cloud-nuke aws --exclude-resource-type s3 --exclude-region us-east-2

To nuke resources based on their age, use --older-than value

This will only delete resources older than this specified value. Can be any valid duration, such as 10m or 8h. (default: "0s") This will accept input in “ms”, “s”, “m”, “h”.

Example: to delete any snapshots older than 2 days,

~$ cloud-nuke aws --resource-type snap --older-than 48h --region us-west-1