Aws cli ec2 list security groups

In this article let’s discuss about Aws cli ec2 list security groups. Let’s go through the following methods without any delay.

Method 1:

# Get EC2 Security Group
awsProfile="awsProfileName" # Use your aws profile name
instanceId="i-00000000000000000" # Enter instance ID
awsQuery="Reservations[].Instances[].{SecurityGroups:SecurityGroups}[0]"
aws --profile "$awsProfile" ec2 describeInstance --instance-ids "$instanceId" --query "$awsQuery"

Hope the above solution works.

Realted Posts : Bash message partial match