def get_resources(self) -> List[Resource]: client = self.vpc_options.client("autoscaling") resources_found = [] response = client.describe_auto_scaling_groups() if self.vpc_options.verbose: message_handler("Collecting data from Autoscaling Groups...", "HEADER") for data in response["AutoScalingGroups"]: asg_subnets = data["VPCZoneIdentifier"].split(",") # Using subnet to check VPC subnets = describe_subnet( vpc_options=self.vpc_options, subnet_ids=asg_subnets ) if subnets is not None: # Iterate subnet to get VPC for data_subnet in subnets["Subnets"]: if data_subnet["VpcId"] == self.vpc_options.vpc_id: asg_name = data["AutoScalingGroupName"] digest = ResourceDigest( id=asg_name, type="aws_autoscaling_group" ) if "LaunchConfigurationName" in data: details = "Using LaunchConfigurationName {0}".format( data["LaunchConfigurationName"] ) else: details = "Using Launch Template" resources_found.append( Resource( digest=digest, name=asg_name, details=details, group="compute", tags=resource_tags(data), ) ) self.relations_found.append( ResourceEdge( from_node=digest, to_node=ResourceDigest( id=data_subnet["SubnetId"], type="aws_subnet" ), ) ) return resources_found
def get_resources(self) -> List[Resource]: client = self.vpc_options.client("mediaconnect") resources_found = [] response = client.list_flows() if self.vpc_options.verbose: message_handler("Collecting data from Media Connect...", "HEADER") for data in response["Flows"]: tags_response = client.list_tags_for_resource( ResourceArn=data["FlowArn"]) data_flow = client.describe_flow(FlowArn=data["FlowArn"]) if "VpcInterfaces" in data_flow["Flow"]: for data_interfaces in data_flow["Flow"]["VpcInterfaces"]: # Using subnet to check VPC subnets = describe_subnet( vpc_options=self.vpc_options, subnet_ids=data_interfaces["SubnetId"], ) if subnets is not None: if subnets["Subnets"][0][ "VpcId"] == self.vpc_options.vpc_id: digest = ResourceDigest(id=data["FlowArn"], type="aws_media_connect") resources_found.append( Resource( digest=digest, name=data["Name"], details= "Flow using VPC {} in VPC Interface {}". format(self.vpc_options.vpc_id, data_interfaces["Name"]), group="mediaservices", tags=resource_tags(tags_response), )) self.relations_found.append( ResourceEdge( from_node=digest, to_node=ResourceDigest( id=data_interfaces["SubnetId"], type="aws_subnet", ), )) return resources_found
def get_resources(self) -> List[Resource]: client = self.vpc_options.client("sagemaker") resources_found = [] response = client.list_training_jobs() if self.vpc_options.verbose: message_handler("Collecting data from Sagemaker Training Job...", "HEADER") for data in response["TrainingJobSummaries"]: tags_response = client.list_tags( ResourceArn=data["TrainingJobArn"], ) training_job = client.describe_training_job( TrainingJobName=data["TrainingJobName"]) if "VpcConfig" in training_job: for subnets in training_job["VpcConfig"]["Subnets"]: # Using subnet to check VPC subnet = describe_subnet(vpc_options=self.vpc_options, subnet_ids=subnets) if subnet is not None: if subnet["Subnets"][0][ "VpcId"] == self.vpc_options.vpc_id: sagemaker_trainingjob_digest = ResourceDigest( id=data["TrainingJobArn"], type="aws_sagemaker_training_job", ) resources_found.append( Resource( digest=sagemaker_trainingjob_digest, name=data["TrainingJobName"], details="", group="ml", tags=resource_tags(tags_response), )) self.relations_found.append( ResourceEdge( from_node=sagemaker_trainingjob_digest, to_node=ResourceDigest(id=subnets, type="aws_subnet"), )) return resources_found
def get_resources(self) -> List[Resource]: client = self.vpc_options.client("efs") resources_found = [] # get filesystems available response = client.describe_file_systems() if self.vpc_options.verbose: message_handler("Collecting data from EFS Mount Targets...", "HEADER") for data in response["FileSystems"]: filesystem = client.describe_mount_targets( FileSystemId=data["FileSystemId"]) nametag = get_name_tag(data) filesystem_name = data[ "FileSystemId"] if nametag is None else nametag # iterate filesystems to get mount targets for datafilesystem in filesystem["MountTargets"]: # Using subnet to check VPC subnets = describe_subnet( vpc_options=self.vpc_options, subnet_ids=datafilesystem["SubnetId"]) if subnets is not None: if subnets["Subnets"][0][ "VpcId"] == self.vpc_options.vpc_id: digest = ResourceDigest(id=data["FileSystemId"], type="aws_efs_file_system") resources_found.append( Resource( digest=digest, name=filesystem_name, details="", group="storage", tags=resource_tags(data), )) self.relations_found.append( ResourceEdge( from_node=digest, to_node=ResourceDigest( id=datafilesystem["SubnetId"], type="aws_subnet"), )) return resources_found
def get_resources(self) -> List[Resource]: client = self.vpc_options.client("sagemaker") resources_found = [] response = client.list_notebook_instances() if self.vpc_options.verbose: message_handler( "Collecting data from Sagemaker Notebook instances...", "HEADER") for data in response["NotebookInstances"]: notebook_instance = client.describe_notebook_instance( NotebookInstanceName=data["NotebookInstanceName"]) tags_response = client.list_tags( ResourceArn=data["NotebookInstanceArn"], ) # Using subnet to check VPC subnets = describe_subnet(vpc_options=self.vpc_options, subnet_ids=notebook_instance["SubnetId"]) if subnets is not None: if subnets["Subnets"][0]["VpcId"] == self.vpc_options.vpc_id: sagemaker_notebook_digest = ResourceDigest( id=data["NotebookInstanceArn"], type="aws_sagemaker_notebook_instance", ) resources_found.append( Resource( digest=sagemaker_notebook_digest, name=data["NotebookInstanceName"], details="", group="ml", tags=resource_tags(tags_response), )) self.relations_found.append( ResourceEdge( from_node=sagemaker_notebook_digest, to_node=ResourceDigest( id=notebook_instance["SubnetId"], type="aws_subnet"), )) return resources_found
def get_resources(self) -> List[Resource]: client = self.vpc_options.client("emr") resources_found = [] response = client.list_clusters() if self.vpc_options.verbose: message_handler("Collecting data from EMR Clusters...", "HEADER") for data in response["Clusters"]: cluster = client.describe_cluster(ClusterId=data["Id"]) # Using subnet to check VPC subnets = describe_subnet( vpc_options=self.vpc_options, subnet_ids=cluster["Cluster"]["Ec2InstanceAttributes"]["Ec2SubnetId"], ) if subnets is not None: if subnets["Subnets"][0]["VpcId"] == self.vpc_options.vpc_id: digest = ResourceDigest(id=data["Id"], type="aws_emr_cluster") resources_found.append( Resource( digest=digest, name=data["Name"], details="", group="compute", tags=resource_tags(cluster["Cluster"]), ) ) self.relations_found.append( ResourceEdge( from_node=digest, to_node=ResourceDigest( id=cluster["Cluster"]["Ec2InstanceAttributes"][ "Ec2SubnetId" ], type="aws_subnet", ), ) ) return resources_found
def get_resources(self) -> List[Resource]: client = self.vpc_options.client("ecs") ec2_client = self.vpc_options.client("ec2") resources_found = [] clusters_list = client.list_clusters() response = client.describe_clusters( clusters=clusters_list["clusterArns"], include=["TAGS"]) if self.vpc_options.verbose: message_handler("Collecting data from ECS Cluster...", "HEADER") # pylint: disable=too-many-nested-blocks for data in response["clusters"]: # Searching all cluster services paginator = client.get_paginator("list_services") pages = paginator.paginate(cluster=data["clusterName"]) for services in pages: if len(services["serviceArns"]) > 0: service_details = client.describe_services( cluster=data["clusterName"], services=services["serviceArns"], ) for data_service_detail in service_details["services"]: if data_service_detail["launchType"] == "FARGATE": service_subnets = data_service_detail[ "networkConfiguration"]["awsvpcConfiguration"][ "subnets"] # Using subnet to check VPC subnets = describe_subnet( vpc_options=self.vpc_options, subnet_ids=service_subnets, ) if subnets is not None: # Iterate subnet to get VPC for data_subnet in subnets["Subnets"]: if data_subnet[ "VpcId"] == self.vpc_options.vpc_id: cluster_digest = ResourceDigest( id=data["clusterArn"], type="aws_ecs_cluster", ) resources_found.append( Resource( digest=cluster_digest, name=data["clusterName"], details="", group="container", tags=resource_tags(data), )) self.relations_found.append( ResourceEdge( from_node=cluster_digest, to_node=ResourceDigest( id=data_subnet["SubnetId"], type="aws_subnet", ), )) else: # EC2 services require container instances, list of them should be fine for now pass # Looking for container instances - they are dynamically associated, so manual review is necessary list_paginator = client.get_paginator("list_container_instances") list_pages = list_paginator.paginate(cluster=data["clusterName"]) for list_page in list_pages: if len(list_page["containerInstanceArns"]) == 0: continue container_instances = client.describe_container_instances( cluster=data["clusterName"], containerInstances=list_page["containerInstanceArns"], ) ec2_ids = [] for instance_details in container_instances[ "containerInstances"]: ec2_ids.append(instance_details["ec2InstanceId"]) paginator = ec2_client.get_paginator("describe_instances") pages = paginator.paginate(InstanceIds=ec2_ids) for page in pages: for reservation in page["Reservations"]: for instance in reservation["Instances"]: for network_interfaces in instance[ "NetworkInterfaces"]: if (network_interfaces["VpcId"] == self.vpc_options.vpc_id): cluster_instance_digest = ResourceDigest( id=instance["InstanceId"], type="aws_ecs_cluster", ) resources_found.append( Resource( digest=cluster_instance_digest, name=data["clusterName"], details="Instance in EC2 cluster", group="container", tags=resource_tags(data), )) self.relations_found.append( ResourceEdge( from_node=cluster_instance_digest, to_node=ResourceDigest( id=instance["InstanceId"], type="aws_instance", ), )) return resources_found