From b6dabe2ee2e7da3915a6aa2b89c99aac6e83916c Mon Sep 17 00:00:00 2001 From: shiva kumar Date: Thu, 19 Dec 2024 17:37:42 +0530 Subject: [PATCH] unused aws instace and vpcs cleanup Signed-off-by: shiva kumar --- scripts/awscleanup.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/scripts/awscleanup.sh b/scripts/awscleanup.sh index b4a386f1..113524f5 100755 --- a/scripts/awscleanup.sh +++ b/scripts/awscleanup.sh @@ -14,7 +14,6 @@ instances=$(aws ec2 describe-instances \ --query "Reservations[].Instances[].InstanceId" \ --output text | tr -d '\r' | tr '\n' ' ') for instance in $instances; do - echo "Terminating instance: $instance" aws ec2 terminate-instances --instance-ids "$instance" done @@ -29,14 +28,12 @@ for sg in $security_groups; do --query "NetworkInterfaces[].NetworkInterfaceId" \ --output text | tr -d '\r' | tr '\n' ' ') for eni in $enis; do - echo "Terminating delete-security-group: $eni" aws ec2 modify-network-interface-attribute \ --network-interface-id "$eni" \ --groups "$(aws ec2 describe-security-groups \ --query 'SecurityGroups[?GroupName==`default`].GroupId' \ --output text)" done - echo "Terminating delete-security-group: $sg" aws ec2 delete-security-group --group-id "$sg" done @@ -46,7 +43,6 @@ subnets=$(aws ec2 describe-subnets \ --query "Subnets[].SubnetId" \ --output text | tr -d '\r' | tr '\n' ' ') for subnet in $subnets; do - echo "Terminating delete-subnet: $subnet" aws ec2 delete-subnet --subnet-id "$subnet" done @@ -71,10 +67,9 @@ for rt in $route_tables; do first_rt=$rt else aws ec2 replace-route-table-association --association-id $assoc_id --route-table-id $first_rt - echo "Terminating delete-route-table: $rt" fi done - aws ec2 delete-route-table --route-table-id "$rt" + aws ec2 delete-route-table --route-table-id "$rt" 2>>/dev/null done # Delete Internet Gateway @@ -83,7 +78,6 @@ internet_gateways=$(aws ec2 describe-internet-gateways \ --query "InternetGateways[].InternetGatewayId" \ --output text | tr -d '\r' | tr '\n' ' ') for igw in $internet_gateways; do - echo "Terminating delete-internet-gateway: $igw" aws ec2 detach-internet-gateway --internet-gateway-id "$igw" --vpc-id "$vpc" aws ec2 delete-internet-gateway --internet-gateway-id "$igw" done @@ -93,7 +87,6 @@ done attempts=0 echo "All resource Deleted for VPC: $vpc , now delete vpc" while [ $attempts -lt 3 ]; do - echo "Attempting to delete VPC: $vpc (Attempt $((attempts+1)))" if aws ec2 delete-vpc --vpc-id $vpc; then echo "Successfully deleted VPC: $vpc" break