Created
December 29, 2025 16:08
-
-
Save atulkamble/7f2274c1ddf7c9ee0faa8d8be7eee827 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| REGION="us-east-1" | |
| echo "⚠️ Deleting AWS resources in region: $REGION" | |
| sleep 3 | |
| # ---------------- EC2 ---------------- | |
| echo "Deleting EC2 instances..." | |
| aws ec2 describe-instances --region $REGION \ | |
| --query "Reservations[].Instances[].InstanceId" \ | |
| --output text | xargs -r aws ec2 terminate-instances --region $REGION | |
| echo "Waiting for EC2 termination..." | |
| aws ec2 wait instance-terminated --region $REGION \ | |
| --instance-ids $(aws ec2 describe-instances --region $REGION \ | |
| --query "Reservations[].Instances[].InstanceId" --output text) | |
| # ---------------- EBS ---------------- | |
| echo "Deleting EBS volumes..." | |
| aws ec2 describe-volumes --region $REGION \ | |
| --query "Volumes[].VolumeId" --output text | \ | |
| xargs -r aws ec2 delete-volume --region $REGION | |
| # ---------------- AMI ---------------- | |
| echo "Deregistering AMIs..." | |
| aws ec2 describe-images --region $REGION --owners self \ | |
| --query "Images[].ImageId" --output text | \ | |
| xargs -r aws ec2 deregister-image --region $REGION | |
| # ---------------- ELB ---------------- | |
| echo "Deleting Load Balancers..." | |
| aws elbv2 describe-load-balancers --region $REGION \ | |
| --query "LoadBalancers[].LoadBalancerArn" --output text | \ | |
| xargs -r aws elbv2 delete-load-balancer --region $REGION | |
| # ---------------- ASG ---------------- | |
| echo "Deleting Auto Scaling Groups..." | |
| aws autoscaling describe-auto-scaling-groups --region $REGION \ | |
| --query "AutoScalingGroups[].AutoScalingGroupName" --output text | \ | |
| while read asg; do | |
| aws autoscaling update-auto-scaling-group \ | |
| --auto-scaling-group-name "$asg" \ | |
| --min-size 0 --max-size 0 --desired-capacity 0 --region $REGION | |
| aws autoscaling delete-auto-scaling-group \ | |
| --auto-scaling-group-name "$asg" --force-delete --region $REGION | |
| done | |
| # ---------------- ECS ---------------- | |
| echo "Deleting ECS services and clusters..." | |
| for cluster in $(aws ecs list-clusters --region $REGION --query "clusterArns[]" --output text); do | |
| for service in $(aws ecs list-services --cluster $cluster --region $REGION --query "serviceArns[]" --output text); do | |
| aws ecs update-service --cluster $cluster --service $service \ | |
| --desired-count 0 --region $REGION | |
| aws ecs delete-service --cluster $cluster --service $service \ | |
| --force --region $REGION | |
| done | |
| aws ecs delete-cluster --cluster $cluster --region $REGION | |
| done | |
| # ---------------- EKS ---------------- | |
| echo "Deleting EKS clusters..." | |
| aws eks list-clusters --region $REGION --query "clusters[]" --output text | \ | |
| xargs -r -n1 aws eks delete-cluster --region $REGION --name | |
| # ---------------- S3 ---------------- | |
| echo "Deleting S3 buckets..." | |
| for bucket in $(aws s3api list-buckets --query "Buckets[].Name" --output text); do | |
| aws s3 rb s3://$bucket --force | |
| done | |
| # ---------------- RDS ---------------- | |
| echo "Deleting RDS instances..." | |
| aws rds describe-db-instances --region $REGION \ | |
| --query "DBInstances[].DBInstanceIdentifier" --output text | \ | |
| xargs -r aws rds delete-db-instance \ | |
| --skip-final-snapshot --region $REGION --db-instance-identifier | |
| # ---------------- Lambda ---------------- | |
| echo "Deleting Lambda functions..." | |
| aws lambda list-functions --region $REGION \ | |
| --query "Functions[].FunctionName" --output text | \ | |
| xargs -r aws lambda delete-function --region $REGION --function-name | |
| # ---------------- CloudWatch Logs ---------------- | |
| echo "Deleting CloudWatch log groups..." | |
| aws logs describe-log-groups --region $REGION \ | |
| --query "logGroups[].logGroupName" --output text | \ | |
| xargs -r aws logs delete-log-group --region $REGION --log-group-name | |
| echo "✅ AWS cleanup completed (region: $REGION)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment