Is there a way to nuke all AWS resources in an AWS account?

Phelodas picture Phelodas · Mar 30, 2017 · Viewed 14.6k times · Source

I have an AWS account where multiple EC2 instances, load balancers, target groups, security groups etc are setup by multiple owners. We use terraform to set this up but sometimes due to corruption, the state becomes inconsistent. Current mechanism to recover is to manually destroy all resources in that account owned by a particular owner. Is there an easy way to nuke all resources in an AWS account belonging to a particular owner?

Answer

Shwetabh Shekhar picture Shwetabh Shekhar · Nov 28, 2019

There is no way to delete all resources in an account owned by a particular user but there is a way to delete all resources in an account.

You can use aws-nuke which was created somewhat out of the same use case you described.

  1. At first, you need to set an account alias for your account.
  2. You must create a config file.
  3. Then you can list down all resources that will be deleted using the following command:

    aws-nuke -c config/nuke-config.yml --profile aws-nuke-example

  4. Add --no-dry-run option to permanently delete all resources in the same command.

  5. There are also multiple filter options available such as target, resource type, exclude, etc. that you can leverage to suit your needs.