Posts

Showing posts from September, 2022

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

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

  Hi guys, If you are wondering How can I get the ID of an AWS security group if I know the name? Here is the solution. Get the Security ID with the wild card Name. #!/bin/bash #Author Praveen SearchString=<*YourSearchString*> # Note : wild cards supported for VPCS in `aws ec2 --output text --query 'Vpcs[*].{VpcId:VpcId}' describe-vpcs` ; do aws ec2 describe-security-groups --filter Name=vpc-id,Values=$VPCS Name=group-name,Values=$searchstring --query 'SecurityGroups[*].[GroupId]' --output text done 2. With the above solution we can automate the other tasks. eg: add tags to security groups. for VPCS in `aws ec2 --output text --query 'Vpcs[*].{VpcId:VpcId}' describe-vpcs` ; do echo " Tagging Search String Created Security Groups" aws ec2 describe-security-groups --filter Name=vpc-id,Values=$VPCS Name=group- name,Values=$searchstring --query 'SecurityGroups[*].[GroupId]' --output text | xargs - I {} aws ...