How to Delete AWS Accounts
Learn the step-by-step instructions for deleting AWS accounts that are no longer needed or were provisioned by accident. We cover renaming email addresses to avoid future conflicts, using cloud-nuke to delete all resources, and manually closing the account through the AWS Console. It also includes recommendations for renaming or repurposing accounts to avoid the overhead of deletion.
Problem
Sometimes accounts are provisioned that are no longer needed or were provisioned by accident. AWS provides no easy programmatic way to destroy accounts. The following ClickOps method is required to destroy the account.
Email addresses associated with AWS accounts are globally unique and cannot be reused even after the account deletion. If you ever intend to use the email address again with AWS on another account, we strongly recommend that you first rename the email address on record before proceeding to delete the account.
Solution
We recommend renaming or repurposing accounts rather than deleting them due to the overhead and complexity of the deletion process.
1 Delete All Account Resources
Closing an account might not automatically terminate all active resources. You may continue to incur charges for active resources even after closing the account. To avoid tedious manual steps, leverage cloud-nuke to delete all resources.
Install cloud-nuke:
brew install cloud-nuke
Dry run to see what will be deleted:
cloud-nuke aws --dry-run
Delete all resources (WARNING: This will delete ALL resources in the account):
cloud-nuke aws
Export required AWS config for running cloud-nuke:
Save the following in .envrc:
# or wherever the configuration file is
export AWS_CONFIG_FILE=rootfs/etc/aws-config/aws-config-teams
# This is necessary for cloud-nuke
export AWS_SDK_LOAD_CONFIG=true
AWS_PROFILE=core-gbl-root-admin cloud-nuke aws --dry-run
Instead of using the AWS profile, you can also use the SuperAdmin user credentials directly. This is often simpler for one-off operations like account deletion.
Create a shell script to automate cloud-nuke across accounts:
Create nuke-echo.sh:
#!/usr/bin/env bash
cat rootfs/etc/aws-config/aws-config-teams | grep '\[profile' | cut -d' ' -f2 | cut -d']' -f1 | grep admin | while read profile; do echo AWS_PROFILE=$profile cloud-nuke aws $@; done
Run with specific regions and exclusions:
./nuke-echo.sh --region us-east-2 --region us-west-2 --region eu-west-3 --exclude-resource-type s3 --exclude-resource-type guardduty --exclude-resource-type transit-gateway
Delete resources in the following order for best results:
- Security accounts
- Audit accounts
- Platform accounts (dev, staging, qa, prod, perf, sandbox)
- Corp accounts
- Auto accounts
- Network accounts (due to transit gateway)
Consider skipping:
- DNS accounts
- Identity accounts
- Root accounts
Skip the following resources until the very end:
iam- due to IAM roles used to initiate cloud-nukes3- due to the time it takes to delete S3 objectsguardduty- controlled by security account across all accountsasg- can fail to destroy EKS ASGstransit-gateway- controlled by network account