def get_security_group_port_open(self, security_group_id, port):
try:
client = boto3.client('ec2',
aws_access_key_id=self.access_key_id,
aws_secret_access_key=self.secret_access_key,
region_name=self.region_name)
except Exception as e:
raise AWSException("There was an error connecting to EC2: %s" % e)
try:
response = client.describe_security_groups(GroupIds=[security_group_id])
# Loop through all of the security group permissions and if the port
for ip_permission in response["SecurityGroups"][0]["IpPermissions"]:
if ip_permission["FromPort"] == port and ip_permission["ToPort"] == port:
return True
return False
except botocore.exceptions.ClientError as e:
raise AWSException("There was an error describing the security group: %s" %
e.response["Error"]["Message"])
评论列表
文章目录