List SecurityGroups for Single Instance with the CLI

Assuming you know the instance ID, i-06e787dbebbfgee09 for example, you can run the below to list the associated SecurityGroups:

$ aws ec2 describe-security-groups --group-ids $(aws ec2 describe-instances --instance-id i-06e787dbebbfgee09 --query "Reservations[].Instances[].SecurityGroups[].GroupId[]" --output text) --output table

Obviously make sure you change the above instance ID to your own.

Be the first to comment

Leave a Reply