# EKS 삭제 # ALB 삭제 # VPC 삭제 # CloudWatch 로그 삭제 # ECR 이미지 삭제 # KMS 삭제cat <<'EOF' > aws-full-cleanup.ps1 ------------------------- Write-Host "🚨 AWS 전체 리소스 정리 스크립트 시작" -ForegroundColor Red $confirm = Read-Host "정말 실행하려면 YES 입력" if ($confirm -ne "YES") { Write-Host "취소되었습니다." exit } # 모든 리전 가져오기 $regions = (aws ec2 describe-regions --query "Regions[].RegionName" --output text).Split("`t") foreach ($region in $regions) { Write-Host "`n🔥 Region: $region" #################################### # 1. EKS 삭제 #################################### $clusters = aws eks list-clusters --region $region --query "clusters[]" --output text if ($clusters) { foreach ($c in $clusters.Split("`t")) { Write-Host "Deleting EKS: $c" aws eks delete-cluster --name $c --region $region } } #################################### # 2. ALB / NLB 삭제 #################################### $lbs = aws elbv2 describe-load-balancers --region $region --query "LoadBalancers[].LoadBalancerArn" --output text if ($lbs) { foreach ($lb in $lbs.Split("`t")) { Write-Host "Deleting LoadBalancer: $lb" aws elbv2 delete-load-balancer --load-balancer-arn $lb --region $region } } #################################### # 3. ECR 이미지 삭제 #################################### $repos = aws ecr describe-repositories --region $region --query "repositories[].repositoryName" --output text if ($repos) { foreach ($repo in $repos.Split("`t")) { Write-Host "Deleting ECR repo: $repo" aws ecr delete-repository --repository-name $repo --region $region --force } } #################################### # 4. CloudWatch Log 삭제 #################################### $logs = aws logs describe-log-groups --region $region --query "logGroups[].logGroupName" --output text if ($logs) { foreach ($lg in $logs.Split("`t")) { Write-Host "Deleting LogGroup: $lg" aws logs delete-log-group --log-group-name $lg --region $region } } #################################### # 5. VPC 삭제 #################################### $vpcs = aws ec2 describe-vpcs --region $region --query "Vpcs[].VpcId" --output text if ($vpcs) { foreach ($vpc in $vpcs.Split("`t")) { Write-Host "Processing VPC: $vpc" # 인터넷 게이트웨이 분리 $igws = aws ec2 describe-internet-gateways --region $region --filters Name=attachment.vpc-id,Values=$vpc --query "InternetGateways[].InternetGatewayId" --output text foreach ($igw in $igws.Split("`t")) { aws ec2 detach-internet-gateway --internet-gateway-id $igw --vpc-id $vpc --region $region aws ec2 delete-internet-gateway --internet-gateway-id $igw --region $region } # 서브넷 삭제 $subnets = aws ec2 describe-subnets --region $region --filters Name=vpc-id,Values=$vpc --query "Subnets[].SubnetId" --output text foreach ($sub in $subnets.Split("`t")) { aws ec2 delete-subnet --subnet-id $sub --region $region } # VPC 삭제 aws ec2 delete-vpc --vpc-id $vpc --region $region } } #################################### # 6. KMS 삭제 #################################### $keys = aws kms list-keys --region $region --query "Keys[].KeyId" --output text if ($keys) { foreach ($key in $keys.Split("`t")) { Write-Host "Scheduling KMS delete: $key" aws kms schedule-key-deletion --key-id $key --pending-window-in-days 7 --region $region } } } Write-Host "`n✅ 모든 리전 정리 명령 실행 완료" EOF pwsh aws-full-cleanup.ps1 ----------------------------- # 또는 powershell ./aws-full-cleanup.ps1