AWS CLI Get Security Group ID with Name. Python Boto3 [ wild card support] Python Boto3

 """

Author Praveen

This Simple Boto Script will list the AWS  security group with name provide [ Wildcard supported]


"""

import boto3

AWS_REGION = "us-west-2"

fullauth = boto3.session.Session(profile_name='<YourProfile>')

ec2 = fullauth.client('ec2' , region_name=AWS_REGION)

group_name = '*<YourSearchString>'

response = ec2.describe_security_groups(

    Filters=[

        dict(Name='group-name', Values=[group_name])

    ]

)

for securityGroup in response['SecurityGroups']:

   print("SG ID: {}, Name: {}".format(securityGroup['GroupId'], securityGroup['GroupName'])) #This will list Security Group Name along with Security Group ID 

   print("SG ID: {}".format(securityGroup['GroupId'])) # This will List Only Security Group IDS

Comments

Popular posts from this blog

AWS CLI Get Security Group ID with Name.[ wild card support] Bash Script

AMI Age Calculator of Running AWS EC2 Instances and Generate CSV Report