An EC2 instance is a virtual server in Amazon's Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure. You can connect the AWS using some python SDK as well. To describe the security group, you can use the below script.
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
response = ec2.describe_security_groups(GroupIds=['SECURITY_GROUP_ID'])
except ClientError as e: