aws opsworks stop-instance --instance-id xxxx-xxxx-... --force --region us-east-1 --profile example
インストール:
git clone https://github.com/aws-samples/ec2-classic-resource-finder.git cd ec2-classic-resource-finder/ chmod +x *.sh
1 アカウントのみ:
export AWS_PROFILE=user1-readonly ./Classic-Resource-Finder.sh # 出力CSV Classic_Auto_Scaling_Groups.csv Classic_ClassicLink_VPCs.csv Classic_CLBs.csv Classic_EC2_Instances.csv Classic_EIPs.csv Classic_ElastiCache_Clusters.csv Classic_OpsWorks_Stacks.csv Classic_Platform_Status.csv Classic_RDS_Instances.csv Classic_Redshift_Clusters.csv Classic_SGs.csv
i-0d632aa76425ef607,ap-northeast-1 i-abcdef1234567890a,ap-northeast-1
in_csv=./Classic_EIPs.csv out_csv=${in_csv}.name.txt cat $in_csv | tr -d '"' | while IFS=$',' read profile region public_ip instance_id || [ -n "${a}" ]; do \ aws ec2 describe-instances --instance-ids $instance_id --profile $profile --region $region --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value|[0]' --output text 2>&1 | perl -ne 's/^\n//;print;' >> $out_csv; \ done
organization account:
export AWS_PROFILE=org-user1 ./multi-account-wrapper.sh -r my-assume-role-readonly -f "Classic-Resource-Finder.sh"
for account in `AWS_PROFILE=org-user1 aws organizations list-accounts...
# if [[ ! $ROLESESSIONNAME =~ $ROLESESSIONNAMEREGEX ]] ... # fi
profile=example region=ap-northeast-1 # EC2-Classicかつ、ec2で使ってないEIPを列挙 aws ec2 describe-addresses --filters "Name=domain,Values=standard" "Name=instance-id,Values=" --profile $profile --region $region > ${profile}.${region}.eip.json # EIP削除 jq -r '.Addresses[].PublicIp' ${profile}.${region}.eip.json | xargs -i aws ec2 release-address --public-ip {} --profile $profile --region $region