List of usage examples for com.amazonaws.services.ec2 AmazonEC2Client describeVpcs
@Override
public DescribeVpcsResult describeVpcs()
From source file:io.macgyver.plugin.cloud.aws.scanner.VPCScanner.java
License:Apache License
@Override public void scan(Region region) { AmazonEC2Client c = getAWSServiceClient().createEC2Client(region); DescribeVpcsResult result = c.describeVpcs(); GraphNodeGarbageCollector gc = newGarbageCollector().region(region).label("AwsVpc"); NeoRxClient neoRx = getNeoRxClient(); Preconditions.checkNotNull(neoRx);//from w w w . j a va2s .c om result.getVpcs().forEach(it -> { try { ObjectNode n = convertAwsObject(it, region); String cypher = "merge (x:AwsVpc {aws_arn:{aws_arn}}) set x+={props} set x.updateTs=timestamp() return x"; String mapToSubnetCypher = "match (y:AwsSubnet {aws_vpcId:{aws_vpcId}}), " + "(x:AwsVpc {aws_arn:{aws_arn}}) " + "merge (x)-[r:CONTAINS]->(y) set r.updateTs=timestamp()"; neoRx.execCypher(cypher, "aws_arn", n.path("aws_arn").asText(), "props", n) .forEach(gc.MERGE_ACTION); neoRx.execCypher(mapToSubnetCypher, "aws_arn", n.path("aws_arn").asText(), "aws_vpcId", n.path("aws_vpcId").asText()); } catch (RuntimeException e) { logger.warn("problem scanning VPC", e); } }); String mapAccountCypher = "match (x:AwsAccount {aws_account:{aws_account}}), (y:AwsVpc {aws_account:{aws_account}}) " + "merge (x)-[r:OWNS]->(y) set r.updateTs=timestamp()"; String mapRegionCypher = "match (x:AwsVpc {aws_region:{aws_region}}), (y:AwsRegion {aws_regionName:{aws_region}, aws_account:{aws_account}}) " + "merge (x)-[r:RESIDES_IN]->(y) set r.updateTs=timestamp()"; neoRx.execCypher(mapAccountCypher, "aws_account", getAccountId()); neoRx.execCypher(mapRegionCypher, "aws_region", region.getName(), "aws_account", getAccountId()); gc.invoke(); }