기능 실험이나 훈련을 목적으로 AWS를 사용할 때는 비용이 거의 발생하지 않도록 리소스들을 즉시 지워야 합니다. 그러나 많은 리소스를 사용할 경우 콘솔로 다 일일이 삭제하기에 시간이 많이 들고, 실수로 어떤 리소스를 지우는 것을 까먹어 많은 비용이 발생할 수 있습니다.
이럴 때는 aws-nuke를 사용하면 됩니다. aws-nuke는 AWS 계정에 있는 모든 리소스를 삭제해주는 도구로 리전과 필터를 설정하여 삭제하지 않을 리소스도 정해줄 수 있습니다.
1. aws-nuke 설치
aws-nuke 실행 파일은 github releases에서 받을 수 있습니다.
https://github.com/rebuy-de/aws-nuke/releases
Releases · rebuy-de/aws-nuke
Nuke a whole AWS account and delete all its resources. - rebuy-de/aws-nuke
github.com
운영체제에 맞게 가장 최신의 실행 파일을 다운로드하면 됩니다.
압축을 해제하고 원하는 위치로 실행파일을 옮깁니다. 명령어로 실행할 수 있게 실행파일 이름도 aws-nuke로 바꿉니다.
모든 디렉토리에서 명령어를 실행할 수 있도록 PATH에 실행파일이 있는 디렉토리 위치를 등록합니다.
2. 설정 파일 작성
디렉토리 하나를 생성하고 설정 파일의 역할을 하는 config.yml을 작성합니다.
# config.yml
regions: # 리소스들이 위치하는 Region
- us-east-1
- us-east-2
- us-west-1
- us-west-2
- ap-south-1
- ap-northeast-1
- ap-northeast-2
- ap-northeast-3
- ap-southeast-1
- ap-southeast-2
- ca-central-1
- eu-central-1
- eu-north-1
- eu-west-1
- eu-west-2
- eu-west-3
- sa-east-1
- global
account-blocklist:
- "999999999999" # 리소스를 삭제하면 안 되는 Production Account ID
accounts:
"073813292468": # 리소스들을 정리할 Account ID
filters:
IAMUser:
- "admin" # 리소스 삭제에 사용하는 IAM User
IAMUserPolicyAttachment:
- "admin -> AdministratorAccess"
IAMUserAccessKey:
- "admin -> AKIARCL45OW2KDLJLXWH" # 리소스 삭제에 사용하는 Access Key ID
3. aws-nuke 실행
aws configure로 Access key를 등록합니다.
PS C:\Users\User\Documents\AWS\nuke> aws configure
AWS Access Key ID [****************FIJJ]:
AWS Secret Access Key [****************ht6c]:
Default region name [ap-northeast-2]: ap-northeast-2
Default output format [json]: json
이제 명령어로 aws-nuke를 실행합니다. no-dry-run 옵션을 입력해야 실제 삭제가 진행됩니다. account alias를 입력하고 리소스 스캔을 시작합시다.
PS C:\Users\User\Documents\AWS\nuke> aws-nuke -c config.yml --no-dry-run
aws-nuke version v2.25.0 - Mon Sep 4 07:34:14 UTC 2023 - 2bd22d5e5c0cf6a4011b3c08a5b1c25e2e6c75bd
Do you really want to nuke the account with the ID 073813292468 and the alias 'arcokim'?
Do you want to continue? Enter account alias to continue.
> arcokim
저는 48개의 리소스가 삭제 가능하다고 나왔습니다. account alias를 다시 입력해서 삭제를 시작합니다.
Scan complete: 1130 total, 48 nukeable, 1082 filtered.
Do you really want to nuke these resources on the account with the ID 073813292468 and the alias 'arcokim'?
Do you want to continue? Enter account alias to continue.
> arcokim
삭제가 다 끝났고, Backup-vault와 MFA를 제외하고 모두 삭제된 것을 확인할 수 있습니다.
us-east-1 - AWSBackupVaultAccessPolicy - aws/efs/automatic-backup-vault - failed
global - IAMVirtualMFADevice - arn:aws:iam::073813292468:mfa/root - failed
global - IAMVirtualMFADevice - arn:aws:iam::073813292468:mfa/admin - failed
Removal requested: 0 waiting, 3 failed, 1082 skipped, 45 finished
오늘의 글은 여기까지입니다. 감사합니다!
'AWS' 카테고리의 다른 글
[AWS] EKS - AWS Load Balancer Controller (0) | 2023.09.26 |
---|---|
[AWS] EKS AutoScaling - Karpenter (2) | 2023.09.25 |
[AWS] EKS Node Metadata (IMDS) - EC2 (0) | 2023.09.22 |
[AWS] ArgoCD를 통한 애플리케이션 배포 (with CodeCommit) (0) | 2023.09.19 |
[AWS] EKS AutoScaling - HPA, Cluster Autoscaler (2) | 2023.09.18 |