2021-04-03 Cloud►AWS AWS - 全リージョンのデフォルトVPC削除 デフォルトVPCを削除しても問題ありません。(再作成可) AWS CLI SHELL123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#!/usr/bin/env bashif [ "$AWS_PROFILE" = "" ]; then echo "No AWS_PROFILE set" exit 1fifor region in $(aws ec2 describe-regions --region ap-northeast-1 | jq -r .Regions[].RegionName); do echo "* Region ${region}" # get default vpc vpc=$(aws ec2 --region ${region} \ describe-vpcs --filter Name=isDefault,Values=true \ | jq -r .Vpcs[0].VpcId) if [ "${vpc}" = "null" ]; then echo "No default vpc found" continue fi echo "Found default vpc ${vpc}" # delete internet gateway igw=$(aws ec2 --region ${region} \ describe-internet-gateways --filter Name=attachment.vpc-id,Values=${vpc} \ | jq -r .InternetGateways[0].InternetGatewayId) if [ "${igw}" != "null" ]; then echo "Detaching and deleting internet gateway ${igw}" aws ec2 --region ${region} \ detach-internet-gateway --internet-gateway-id ${igw} --vpc-id ${vpc} aws ec2 --region ${region} \ delete-internet-gateway --internet-gateway-id ${igw} fi # delete subnets subnets=$(aws ec2 --region ${region} \ describe-subnets --filters Name=vpc-id,Values=${vpc} \ | jq -r .Subnets[].SubnetId) if [ "${subnets}" != "null" ]; then for subnet in ${subnets}; do echo "Deleting subnet ${subnet}" aws ec2 --region ${region} \ delete-subnet --subnet-id ${subnet} done fi # delete default vpc echo "Deleting vpc ${vpc}" aws ec2 --region ${region} \ delete-vpc --vpc-id ${vpc}done 再作成「VPC一覧」→「アクション」→「デフォルトVPCを作成」 次の記事 WSL インポート・エクスポート (ディスク移動) 前の記事 npm - パッケージアップデート