aws.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:spark-notebook 作者: mas-dse 项目源码 文件源码
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"])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号