AWS CLI removes all event bridge rules from all regions

PROFILE=
aws --profile $PROFILE configure

#list rules by regions
for REGION in $(aws --profile $PROFILE ec2 describe-regions --all-regions --query "Regions[].{Name:RegionName}" --output text); do 
echo $REGION
aws --profile $PROFILE events list-rules --region=$REGION --query "Rules[].{Name:Name}" --output text
done

#remove targets and rules
for REGION in $(aws --profile $PROFILE ec2 describe-regions --all-regions --query "Regions[].{Name:RegionName}" --output text); do 
for RULE in $(aws --profile $PROFILE events list-rules --region=$REGION --query "Rules[].{Name:Name}" --output text); do
aws --profile $PROFILE events remove-targets --rule $RULE --ids CrossAccountTargetId --region=$REGION && aws --profile $PROFILE events delete-rule --name=$RULE --region=$REGION;
done
done

Leave a comment