Created
November 29, 2021 23:27
-
-
Save alexandrerocco/06664fc437b28757ec6fd6fa4da48d40 to your computer and use it in GitHub Desktop.
Lists unused AWS key pair and delete if needed
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
# List key pairs on the account | |
aws ec2 describe-key-pairs --query 'KeyPairs[*].KeyName' --output table | |
# Find instances that uses a key pair you found out above | |
aws ec2 describe-instances --filters Name=instance-state-name,Values=running Name=key-name,Values="KP-NAME" --query 'Reservations[*].Instances[*].InstanceId' | |
# If you get an empty response, you can opt to delete it with: | |
aws ec2 delete-key-pair --key-name KP-NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment