Are you seriously looking out for a tool that can save your AWS bills while being a FREE tier user? If you’re one of those new AWS account holders who wants to ensure that all the resources get deleted once you finish your testing work, then you should look at “Cloud Nuke”.
Cloud-Nuke is a tool for cleaning up your cloud accounts by nuking (deleting) all resources within them. It’s open-source tool and hosted under GITHUB.
Why Cloud Nuke is so cool?
Unknown Source
The primary purpose of Cloud-Nuke is to delete cloud resources that are not actively in use. This includes virtual machines, storage buckets, databases, load balancers, queues, and other cloud services. By removing these resources, users can avoid incurring unnecessary costs and keep their cloud environments more organized.
Cloud-Nuke operates by utilizing the APIs provided by each cloud provider to identify and delete specified resources. It requires appropriate access credentials and permissions to interact with the cloud provider’s API.
With Cloud Nuke, you can get the below list of work completed in just 2 minutes:
- Deleting all Auto scaling groups in an AWS account
- Deleting all Elastic Load Balancers (Classic and V2) in an AWS account
- Deleting all EBS Volumes in an AWS account
- Deleting all unprotected EC2 instances in an AWS account
- Deleting all AMIs in an AWS account
- Deleting all Snapshots in an AWS account
- Deleting all Elastic IPs in an AWS account
- Deleting all Launch Configurations in an AWS account
- Deleting all ECS services in an AWS account
- Deleting all ECS clusters in an AWS account
- Deleting all EKS clusters in an AWS account
- Deleting all RDS DB instances in an AWS account
- Deleting all Lambda Functions in an AWS account
- Deleting all S3 buckets in an AWS account – except for buckets tagged with Key=cloud-nuke-excluded Value=true
- Deleting all default VPCs in an AWS account
- Revoking the default rules in the un-deletable default security group of a VPC
Without any further delay, let us test drive this tool.
Before using this tool, I had a bunch of EC2 instances up and running for my testing work. These instances were lying around and I really didn’t need them anymore.
Pre-requisite
- Ensure that you have
aws configure
configured.
Download
- Linux System
wget https://github.com/gruntwork-io/cloud-nuke/releases/download/v0.1.24/cloud-nuke_linux_amd64
If you’re on MacOS, ensure that you pick up
wget https://github.com/gruntwork-io/cloud-nuke/releases/download/v0.1.24/cloud-nuke_darwin_amd64
Move the binary to a folder on your PATH.
mv cloud-nuke_darwin_amd64 /usr/local/bin/cloud-nuke.
Add execute permissions to the binary.
chmod u+x /usr/local/bin/cloud-nuke
Test it installed correctly:
cloud-nuke --help.
That’s it. Run the below CLI to clean up the overall AWS resources.
sudo cloud-nuke aws
INFO[2020-12-23T11:33:42Z] The following resource types will be nuked:
INFO[2020-12-23T11:33:42Z] - ami
INFO[2020-12-23T11:33:42Z] - asg
INFO[2020-12-23T11:33:42Z] - ebs
INFO[2020-12-23T11:33:42Z] - ec2
INFO[2020-12-23T11:33:42Z] - ecscluster
INFO[2020-12-23T11:33:42Z] - ecsserv
INFO[2020-12-23T11:33:42Z] - eip
INFO[2020-12-23T11:33:42Z] - ekscluster
INFO[2020-12-23T11:33:42Z] - elb
INFO[2020-12-23T11:33:42Z] - elbv2
INFO[2020-12-23T11:33:42Z] - lambda
INFO[2020-12-23T11:33:42Z] - lc
INFO[2020-12-23T11:33:42Z] - rds
INFO[2020-12-23T11:33:42Z] - s3
INFO[2020-12-23T11:33:42Z] - snap
INFO[2020-12-23T11:33:43Z] Retrieving active AWS resources in [eu-north-1, ap-south-1, eu-west-3, eu-west-2, eu-west-1, ap-northeast-2, ap-northeast-1, sa-east-1, ca-central-1, ap-southeast-1, ap-southeast-2, eu-central-1, us-east-1, us-east-2, us-west-1, us-west-2]
INFO[2020-12-23T11:33:43Z] Checking region [1/16]: eu-north-1
It will ask you to type “nuke” and there you go…
THE NEXT STEPS ARE DESTRUCTIVE AND COMPLETELY IRREVERSIBLE, PROCEED WITH CAUTION!!!
Are you sure you want to nuke all listed resources? Enter 'nuke' to confirm (or exit with ^C): nuke
INFO[2020-12-24T11:47:21Z] Terminating 1 resources in batches
INFO[2020-12-24T11:47:21Z] Deleting all Elastic Load Balancers in region us-east-1
INFO[2020-12-24T11:47:21Z] Deleted ELB: af6820e0fc547433a8b8cdc84c636d4a
INFO[2020-12-24T11:47:21Z] [OK] 1 Elastic Load Balancer(s) deleted in us-east-1
INFO[2020-12-24T11:47:21Z] Terminating 2 resources in batches
INFO[2020-12-24T11:47:21Z] Deleting all V2 Elastic Load Balancers in region us-east-1
INFO[2020-12-24T11:47:21Z] Deleted ELBv2: arn:aws:elasticloadbalancing:us-east-1:567085410233:loadbalancer/net/test-s9jfl-ext/0ecfc28fd2202161
INFO[2020-12-24T11:47:21Z] Deleted ELBv2: arn:aws:elasticloadbalancing:us-east-1:567085410233:loadbalancer/net/test-s9jfl-int/eb345a2c6cb26c1a
INFO[2020-12-24T11:47:21Z] [OK] 2 V2 Elastic Load Balancer(s) deleted in us-east-1
INFO[2020-12-24T11:47:21Z] Terminating 9 resources in batches
INFO[2020-12-24T11:47:21Z] Terminating all EC2 instances in region us-east-1
Connection to ec2-3-238-203-58.compute-1.amazonaws.com closed by remote host.
Connection to ec2-3-238-203-58.compute-1.amazonaws.com closed.
By now, I could see that all of these resources getting terminated. Super cool, isn’t it?
Be Careful…
It’s important to exercise caution while using Cloud-Nuke or any similar resource deletion tool. Before running Cloud-Nuke, it is recommended to thoroughly review the selected resources and ensure that they are not required for any critical systems or applications. Proper testing and verification should be performed to avoid accidental deletion of important resources.
Cloud-Nuke can be a useful tool for automating and simplifying resource cleanup in cloud environments. However, it should be used with caution and in accordance with best practices to avoid any unintended consequences.
Comments are closed.