有時候,我們要清除AWS帳號的資源時,都要一個個去刪除。
這時候aws-nuke
這個工具就派上用場了。
這個工具會根據你的需求去清除你不要的資源,也可以留下某些需要的資源。
就來簡單Demo一下吧~
首先先到aws-nuke的github來下載該套件:

接著將他移動到/usr/bin/
底下(弱弱是用macOSX
,如果你的環境不一樣的話要記得改變)
wget https://github.com/rebuy-de/aws-nuke/releases/download/v2.13.0/aws-nuke-v2.13.0-darwin-amd64
mv aws-nuke-v2.13.0-darwin-amd64 aws-nuke
mv aws-nuke /usr/bin/
這樣就可以使用了。
接下來要來編輯設定檔,這邊我們用example.yaml來使用:
vim example.yaml
---
regions:
- "global"
- "ap-northeast-1"
accounts:
1234567890:
presets:
- "global"
presets:
global:
filters:
EC2VPC:
- property: IsDefault
value: "true"
IAMRole:
- "Role-ABCD"
IAMRolePolicyAttachment:
- "Role-ABCD -> AdministratorAccess"
這邊稍微介紹一下
- region:表示要掃描的區域
- account:表示此帳號的某些資源不被刪除
- presets:這邊是以群組的方式去寫,因為account可能有多組,就不用每個account底下去一筆筆寫。
存擋後,我們就可以使用aws-nuke來試跑:
aws-nuke -c path/as/example.yaml --profile admin
這時候,會跳出一堆會要被刪除以及無法刪除的訊息:
因為會出現太多,這邊只列出最後面的關鍵字
would remove
表示要被刪除的
cannot delete default VPC
表示這是預設的VPC無法被刪除
cannot delete AWS alias
表示這是AWS配發的,也無法被刪除
等確定之後,就可以在後面加上--no-dry-run
去刪除囉。
aws-nuke -c path/as/example.yaml --profile admin --no-dry-run
這樣就會刪除了。