com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer Java Examples

The following examples show how to use com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
private void guaranteeHasAllSubnets(Collection<String> subnetIds, LoadBalancer loadBalancer) {
  Collection<String> subnetsOnLoadBalancer = getSubnetsFromLoadBalancer(loadBalancer);
  Set<String> subnetsToAdd = new HashSet<>();
  for (String subnetId : subnetIds) {
    if (! subnetsOnLoadBalancer.contains(subnetId)) {
      subnetsToAdd.add(subnetId);
    }
  }

  subnetsToAdd = Sets.union(new HashSet<>(subnetsOnLoadBalancer), subnetsToAdd);

  try {
    SetSubnetsRequest subnetsRequest = new SetSubnetsRequest()
        .withLoadBalancerArn(loadBalancer.getLoadBalancerArn())
        .withSubnets(subnetsToAdd);
    elbClient.setSubnets(subnetsRequest);
  } catch (AmazonClientException acexn) {
    LOG.error("Could not attach subnets {} to load balancer {} due to error",
        subnetsToAdd, loadBalancer.getLoadBalancerName(), acexn);
    exceptionNotifier.notify(acexn, ImmutableMap.of(
        "elb", loadBalancer.getLoadBalancerName(),
        "subnets", subnetsToAdd.toString()));
  }
}
 
Example #2
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
private void guaranteeAzEnabled(Collection<BaragonAgentMetadata> agents,
                                Collection<LoadBalancer> loadBalancers) {
  for (LoadBalancer loadBalancer : loadBalancers) {
    Collection<String> azNames = new HashSet<>();
    for (AvailabilityZone availabilityZone : loadBalancer.getAvailabilityZones()) {
      azNames.add(availabilityZone.getZoneName());
    }

    for (BaragonAgentMetadata agent : agents) {
      if (agent.getEc2().getAvailabilityZone().isPresent()
          && ! azNames.contains(agent.getEc2().getAvailabilityZone().get())) {
        guaranteeHasAllSubnets(
            agent.getEc2().getSubnetId().asSet(),
            loadBalancer);
      }
    }
  }
}
 
Example #3
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
/**
 * When this method completes, the target group, the agents, and the loadBalancers are
 * all on the same VPC.
 * The target group, each of the agents, and each of the load balancers should think
 * that they are on the same VPC, otherwise they won't be able to talk to each other.
 *
 *
 * @param targetGroup Group - and consequently all targets - to check
 * @param agents Agents to check
 * @param loadBalancers Load balances to check
 */
private void guaranteeSameVPC(TargetGroup targetGroup,
                              Collection<BaragonAgentMetadata> agents,
                              Collection<LoadBalancer> loadBalancers) {
  String vpcId = targetGroup.getVpcId();

  for (BaragonAgentMetadata agent : agents) {
    if (agent.getEc2().getVpcId().isPresent()) {
      if (! agent.getEc2().getVpcId().get().equals(vpcId)) {
        LOG.error("Agent {} not on same VPC as its target group {}", agent, targetGroup);
        throw new IllegalStateException(String.format("Agent %s not on same VPC as its target group %s", agent, targetGroup));
      }
    } else {
      LOG.error("Agent {} not assigned to a VPC", agent);
      throw new IllegalStateException(String.format("Agent %s not assigned to a VPC", agent));
    }
  }

  for (LoadBalancer loadBalancer : loadBalancers) {
    if (!vpcId.equals(loadBalancer.getVpcId())) {
      LOG.error("Load balancer {} on different VPC from target group {}", loadBalancer, targetGroup);
      throw new IllegalStateException(String.format("Load balancer %s on different VPC from target group %s", loadBalancer, targetGroup));
    }
  }
}
 
Example #4
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that the given baragon agent is attached to the given target group. When this function
 * completes, the baragon agent will be attached to the load balancer, whether or not it originally
 * was.
 *
 * @param baragonAgents BaragonAgent to register with given load balancer
 * @param loadBalancers Load balancer to register with
 */
private void guaranteeRegistered(TrafficSource trafficSource,
                                 TargetGroup targetGroup,
                                 Collection<TargetDescription> targets,
                                 Collection<BaragonAgentMetadata> baragonAgents,
                                 Collection<LoadBalancer> loadBalancers) {
  /*
  - Check that load balancers, baragon agents, target groups are on same VPC
  - Check that load balancers, targets are on same subnet (== AZ)
  - Check that all baragon agents are associated with a target on target group
  - Check that load balancers has listeners, rules to make talk to target group
   */

  if (configuration.isPresent() && configuration.get().isCheckForCorrectVpc()) {
    guaranteeSameVPC(targetGroup, baragonAgents, loadBalancers);
  }

  guaranteeAzEnabled(baragonAgents, loadBalancers);
  guaranteeHasAllTargets(trafficSource, targetGroup, targets, baragonAgents);
  //guaranteeListenersPresent(targetGroup, loadBalancers);
}
 
Example #5
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
private Collection<LoadBalancer> getLoadBalancersByBaragonGroup(Collection<LoadBalancer> allLoadBalancers, BaragonGroup baragonGroup) {
  Set<TrafficSource> trafficSources = baragonGroup.getTrafficSources();
  Set<String> trafficSourceNames = new HashSet<>();
  Collection<LoadBalancer> loadBalancersForGroup = new HashSet<>();

  for (TrafficSource trafficSource : trafficSources) {
    trafficSourceNames.add(trafficSource.getName());
  }

  for (LoadBalancer loadBalancer : allLoadBalancers) {
    if (trafficSourceNames.contains(loadBalancer.getLoadBalancerName())) {
      loadBalancersForGroup.add(loadBalancer);
    }
  }

  return loadBalancersForGroup;
}
 
Example #6
Source File: AlbResource.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@GET
@NoAuth
@Path("/load-balancers/{elbName}")
public LoadBalancer getLoadBalancer(@PathParam("elbName") String elbName) {
  if (config.isPresent()) {
    try {
      Optional<LoadBalancer> maybeLoadBalancer = applicationLoadBalancer.getLoadBalancer(elbName);
      if (maybeLoadBalancer.isPresent()) {
        return maybeLoadBalancer.get();
      } else {
        throw new WebApplicationException(String.format("ELB %s not found", elbName), Status.NOT_FOUND);
      }
    } catch (AmazonClientException exn) {
      throw new BaragonWebException(String.format("AWS client exception %s", exn));
    }
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
Example #7
Source File: AlbResource.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@POST
@Path("/load-balancers/{elbName}/listeners")
public Listener createListeners(@PathParam("elbName") String elbName,
                                @Valid CreateListenerRequest createListenerRequest) {
  if (config.isPresent()) {
      Optional<LoadBalancer> maybeLoadBalancer = applicationLoadBalancer
          .getLoadBalancer(elbName);
      if (maybeLoadBalancer.isPresent()) {
        return applicationLoadBalancer
            .createListener(createListenerRequest
                .withLoadBalancerArn(maybeLoadBalancer.get().getLoadBalancerArn()));
      } else {
        throw new WebApplicationException(String.format("Could not find an elb with name %s", elbName), Status.NOT_FOUND);
      }
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
Example #8
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Collection<LoadBalancer> getAllLoadBalancers() {
  Collection<LoadBalancer> loadBalancers = new HashSet<>();
  DescribeLoadBalancersRequest loadBalancersRequest = new DescribeLoadBalancersRequest();
  DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(loadBalancersRequest);
  String nextPage = result.getNextMarker();
  loadBalancers.addAll(result.getLoadBalancers());

  while (!Strings.isNullOrEmpty(nextPage)) {
    loadBalancersRequest = new DescribeLoadBalancersRequest()
        .withMarker(nextPage);
    result = elbClient.describeLoadBalancers(loadBalancersRequest);
    nextPage = result.getNextMarker();
    loadBalancers.addAll(result.getLoadBalancers());
  }

  return loadBalancers;
}
 
Example #9
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Optional<LoadBalancer> getLoadBalancer(String loadBalancer) {
  DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest()
      .withNames(loadBalancer);

  try {
    List<LoadBalancer> maybeLoadBalancer = elbClient
        .describeLoadBalancers(request)
        .getLoadBalancers();

    if (maybeLoadBalancer.size() > 0) {
      return Optional.of(maybeLoadBalancer.get(0));
    } else {
      return Optional.absent();
    }
  } catch (LoadBalancerNotFoundException notFound) {
    LOG.warn("Could not find load balancer with name {}", loadBalancer);
    return Optional.absent();
  }
}
 
Example #10
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Collection<Listener> getListenersForElb(String elbName) {
  Optional<LoadBalancer> maybeLoadBalancer = getLoadBalancer(elbName);
  if (maybeLoadBalancer.isPresent()) {
    Collection<Listener> listeners = new HashSet<>();
    DescribeListenersRequest listenersRequest = new DescribeListenersRequest()
        .withLoadBalancerArn(maybeLoadBalancer.get().getLoadBalancerArn());
    DescribeListenersResult result = elbClient.describeListeners(listenersRequest);
    String nextMarker = result.getNextMarker();
    listeners.addAll(result.getListeners());

    while (! Strings.isNullOrEmpty(nextMarker)) {
      listenersRequest = new DescribeListenersRequest()
          .withMarker(nextMarker);
      result = elbClient.describeListeners(listenersRequest);
      nextMarker = result.getNextMarker();
      listeners.addAll(result.getListeners());
    }

    return listeners;
  } else {
    return Collections.emptySet();
  }
}
 
Example #11
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private Collection<String> getSubnetsFromLoadBalancer(LoadBalancer loadBalancer) {
  List<AvailabilityZone> availabilityZones = loadBalancer.getAvailabilityZones();
  Set<String> subnetIds = new HashSet<>();

  for (AvailabilityZone availabilityZone : availabilityZones) {
    subnetIds.add(availabilityZone.getSubnetId());
  }

  return subnetIds;
}
 
Example #12
Source File: PublicAccessAutoFix.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the sg list for app elb resource.
 *
 * @param clientMap the client map
 * @param resourceId the resource id
 * @return the sg list for app elb resource
 * @throws Exception the exception
 */
public static List<String> getSgListForAppElbResource(Map<String,Object> clientMap,String resourceId) throws Exception {
    com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing amazonApplicationElasticLoadBalancing = (com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing) clientMap.get("client");
    DescribeLoadBalancersRequest describeLoadBalancersRequest = new DescribeLoadBalancersRequest();
    describeLoadBalancersRequest.setLoadBalancerArns(Arrays.asList(resourceId));
    DescribeLoadBalancersResult balancersResult = amazonApplicationElasticLoadBalancing.describeLoadBalancers(describeLoadBalancersRequest);
    List<LoadBalancer> balancers = balancersResult.getLoadBalancers();
    return balancers.get(0).getSecurityGroups();
}
 
Example #13
Source File: AlbResource.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@GET
@NoAuth
@Path("/load-balancers")
public Collection<LoadBalancer> getAllLoadBalancers() {
  if (config.isPresent()) {
    return applicationLoadBalancer.getAllLoadBalancers();
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
Example #14
Source File: InventoryUtilTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch elb info test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchElbInfoTest() throws Exception {
    
    mockStatic(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.class);
    com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient = PowerMockito.mock(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing.class);
    com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder amazonElasticLoadBalancingClientBuilder = PowerMockito.mock(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonElasticLoadBalancingClientBuilder.standard()).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withCredentials(anyObject())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withRegion(anyString())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.build()).thenReturn(elbClient);
    
    DescribeLoadBalancersResult elbDescResult = new DescribeLoadBalancersResult();
    List<LoadBalancer> elbList = new ArrayList<>();
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setLoadBalancerArn("loadBalancerArn");
    elbList.add(loadBalancer);
    elbDescResult.setLoadBalancers(elbList);
    when(elbClient.describeLoadBalancers(anyObject())).thenReturn(elbDescResult);
    
    com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsResult describeTagsResult = new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsResult();
    List<com.amazonaws.services.elasticloadbalancingv2.model.TagDescription> tagsList = new ArrayList<>();
    com.amazonaws.services.elasticloadbalancingv2.model.TagDescription tagDescription = new com.amazonaws.services.elasticloadbalancingv2.model.TagDescription();
    tagDescription.setResourceArn("loadBalancerArn");
    tagDescription.setTags(new ArrayList<com.amazonaws.services.elasticloadbalancingv2.model.Tag>());
    tagsList.add(tagDescription);
    describeTagsResult.setTagDescriptions(tagsList);
    when(elbClient.describeTags(anyObject())).thenReturn(describeTagsResult);
    assertThat(inventoryUtil.fetchElbInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
    
}
 
Example #15
Source File: LoadBalancerVH.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new load balancer VH.
 *
 * @param elb the elb
 * @param tags the tags
 */
public LoadBalancerVH(LoadBalancer elb,List<Tag> tags, String accessLogBucketName, boolean accessLog){
	lb = elb;
	this.tags = tags;
	this.accessLog = accessLog;
	this.accessLogBucketName = accessLogBucketName;
	availabilityZones = new ArrayList<>();
	subnets = new ArrayList<>();
	this.instances = new ArrayList<>();
	if(lb.getAvailabilityZones()!=null){
	    lb.getAvailabilityZones().forEach(e-> { availabilityZones.add(e.getZoneName());
		                                        subnets.add(e.getSubnetId());});
	}

}
 
Example #16
Source File: LoadBalancerVH.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new load balancer VH.
 *
 * @param elb the elb
 */
public LoadBalancerVH(LoadBalancer elb){
	lb = elb;
	availabilityZones = new ArrayList<>();
	this.instances = new ArrayList<>();
	if(lb.getAvailabilityZones()!=null){
	    lb.getAvailabilityZones().forEach(e-> { availabilityZones.add(e.getZoneName());
           subnets.add(e.getSubnetId());});
	}
}
 
Example #17
Source File: InventoryUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
/**
 * Fetch elb info.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<LoadBalancerVH>> fetchElbInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
	com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient ;
	Map<String,List<LoadBalancerVH>> elbMap = new LinkedHashMap<>();
	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Application ELB\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){
		try{
			if(!skipRegions.contains(region.getName())){
				elbClient = com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.standard().
					 	withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				String nextMarker = null;
				DescribeLoadBalancersResult descElbRslt ;
				List<LoadBalancer> elbList = new ArrayList<>();
				do{
					descElbRslt = elbClient.describeLoadBalancers(new com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest().withMarker(nextMarker));
					elbList.addAll(descElbRslt.getLoadBalancers());
					nextMarker = descElbRslt.getNextMarker();
				}while(nextMarker!=null);

				if(! elbList.isEmpty() ) {
					List<LoadBalancerVH> elbListTemp = new ArrayList<>();
					List<String> elbArns = elbList.stream().map(LoadBalancer::getLoadBalancerArn).collect(Collectors.toList());
					List<com.amazonaws.services.elasticloadbalancingv2.model.TagDescription> tagDescriptions = new ArrayList<>();
					int i = 0;
					List<String> elbArnsTemp  = new ArrayList<>();
					for(String elbArn : elbArns){
						i++;
						elbArnsTemp.add(elbArn);
						if(i%20 == 0){
							tagDescriptions.addAll(elbClient.describeTags(new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest().withResourceArns(elbArnsTemp)).getTagDescriptions());
							elbArnsTemp  = new ArrayList<>();
						}

					}
					if(!elbArnsTemp.isEmpty())
						tagDescriptions.addAll(elbClient.describeTags(new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest().withResourceArns(elbArnsTemp)).getTagDescriptions());

					elbList.parallelStream().forEach(elb->	{
						List<List<com.amazonaws.services.elasticloadbalancingv2.model.Tag>> tagsInfo =  tagDescriptions.stream().filter(tag -> tag.getResourceArn().equals( elb.getLoadBalancerArn())).map(x-> x.getTags()).collect(Collectors.toList());
						List<com.amazonaws.services.elasticloadbalancingv2.model.Tag> tags = new ArrayList<>();
						//****** Changes For Federated Rules Start ******
						String name = elb.getLoadBalancerArn();
						String accessLogBucketName = "";
						boolean accessLog = false;
					if (name != null) {
						com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing appElbClient = com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder
								.standard()
								.withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials))
								.withRegion(region.getName()).build();
						com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancerAttributesRequest request1 = new com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancerAttributesRequest()
								.withLoadBalancerArn(name);
						List<LoadBalancerAttribute> listAccessLogBucketAttri = appElbClient
								.describeLoadBalancerAttributes(request1).getAttributes();
						for (LoadBalancerAttribute help : listAccessLogBucketAttri) {
							String attributeBucketKey = help.getKey();
							String attributeBucketValue = help.getValue();
							if (attributeBucketKey.equalsIgnoreCase("access_logs.s3.enabled")
									&& attributeBucketValue.equalsIgnoreCase("true")) {
								accessLog = true;
							}
							if ((attributeBucketKey.equalsIgnoreCase("access_logs.s3.bucket")
									&& attributeBucketValue != null)) {
								accessLogBucketName = attributeBucketValue;
							}
						}
						//****** Changes For Federated Rules End ******
						if(!tagsInfo.isEmpty())
							tags = tagsInfo.get(0);
						LoadBalancerVH elbTemp = new LoadBalancerVH(elb, tags, accessLogBucketName, accessLog);
						synchronized(elbListTemp){
							elbListTemp.add(elbTemp);
						}
					 }
					});

					log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Application ELB " +region.getName() + " >> "+elbListTemp.size());
					elbMap.put(accountId+delimiter+accountName+delimiter+region.getName(),elbListTemp);
				}
			}
		}catch(Exception e){
			log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
			ErrorManageUtil.uploadError(accountId,region.getName(),"appelb",e.getMessage());
		}
	}
	return elbMap;
}
 
Example #18
Source File: FileManager.java    From pacbot with Apache License 2.0 4 votes vote down vote up
/**
 * Generate target group files.
 *
 * @param targetGrpMap the target grp map
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void generateTargetGroupFiles(Map<String, List<TargetGroupVH>> targetGrpMap) throws IOException {
	String fieldNames;
	String keys;
	fieldNames = "trgtGrp.TargetGroupArn`trgtGrp.TargetGroupName`trgtGrp.vpcid`trgtGrp.protocol`trgtGrp.port`trgtGrp.HealthyThresholdCount`trgtGrp.UnhealthyThresholdCount`trgtGrp.HealthCheckIntervalSeconds`trgtGrp.HealthCheckTimeoutSeconds`trgtGrp.LoadBalancerArns";
	keys = "discoverydate`accountid`accountname`region`targetgrouparn`targetgroupname`vpcid`protocol`port`healthythresholdcount`unhealthythresholdcount`healthcheckintervalseconds`healthchecktimeoutseconds`loadbalancerarns";
	FileGenerator.generateJson(targetGrpMap, fieldNames, "aws-targetgroup.data",keys);

	fieldNames = "trgtGrp.TargetGroupName`targets.target.id";
	keys = "discoverydate`accountid`accountname`region`targetgrouparn`targetgroupid";
	FileGenerator.generateJson(targetGrpMap, fieldNames, "aws-targetgroup-instances.data",keys);

	Map<String, List<LoadBalancerVH>> appElbInstanceMap = new HashMap<>();
	Iterator<Entry<String, List<TargetGroupVH>>> it=  targetGrpMap.entrySet().iterator();

	while(it.hasNext()){
		Entry<String, List<TargetGroupVH>> entry = it.next();
		String accntId= entry.getKey();
		List<TargetGroupVH> trgtList = entry.getValue();
		appElbInstanceMap.putIfAbsent(accntId,new ArrayList<LoadBalancerVH>());
		for(TargetGroupVH trgtGrp : trgtList){
			List<String> elbList = trgtGrp.getTrgtGrp().getLoadBalancerArns();
			for(String elbarn : elbList){
				LoadBalancer elb = new LoadBalancer();
				elb.setLoadBalancerArn(elbarn);
				Matcher appMatcher = Pattern.compile("(?<=loadbalancer/(app|net)/)(.*)(?=/)").matcher(elbarn);
				if(appMatcher.find()){
					elb.setLoadBalancerName(appMatcher.group());
					LoadBalancerVH elbVH = new LoadBalancerVH(elb);
					List<com.amazonaws.services.elasticloadbalancing.model.Instance> instances = new ArrayList<>();
					elbVH.setInstances(instances);
					trgtGrp.getTargets().forEach(trgtHealth -> {
						instances.add(new com.amazonaws.services.elasticloadbalancing.model.Instance(trgtHealth.getTarget().getId()));
					});
					appElbInstanceMap.get(accntId).add(elbVH);
				}
			}
		}
	}
	fieldNames = "lb.LoadBalancerName`Instances.InstanceId";
	keys = "discoverydate`accountid`accountname`region`loadbalancername`instanceid";
	FileGenerator.generateJson(appElbInstanceMap, fieldNames, "aws-appelb-instances.data",keys);
}