software.amazon.awssdk.services.ec2.model.Vpc Java Examples

The following examples show how to use software.amazon.awssdk.services.ec2.model.Vpc. 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: AwsEc2VpcScannerTest.java    From clouditor with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void setUpOnce() throws IOException {
  discoverAssets(
      Ec2Client.class,
      AwsEc2VpcScanner::new,
      api -> {
        when(api.describeVpcs())
            .thenReturn(
                DescribeVpcsResponse.builder()
                    .vpcs(Vpc.builder().vpcId("vpc-1").build())
                    .build());

        when(api.describeStaleSecurityGroups(
                DescribeStaleSecurityGroupsRequest.builder().vpcId("vpc-1").build()))
            .thenReturn(
                DescribeStaleSecurityGroupsResponse.builder()
                    .staleSecurityGroupSet(
                        StaleSecurityGroup.builder().groupId("some-group").build())
                    .build());
      });
}
 
Example #2
Source File: DescribeVPCs.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void describeEC2Vpcs(Ec2Client ec2, String vpcId) {

        try {
            DescribeVpcsRequest request = DescribeVpcsRequest.builder()
                .vpcIds(vpcId)
                .build();

            DescribeVpcsResponse response =
                ec2.describeVpcs(request);

            for (Vpc vpc : response.vpcs()) {
                System.out.printf(
                    "Found vpc with id %s, " +
                            "vpc state %s " +
                            "and tennancy %s",
                    vpc.vpcId(),
                    vpc.stateAsString(),
                    vpc.instanceTenancyAsString());
                }
            } catch (Ec2Exception e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        // snippet-end:[ec2.java2.describe_vpc.main]
    }
 
Example #3
Source File: AwsEc2VpcScanner.java    From clouditor with Apache License 2.0 5 votes vote down vote up
public AwsEc2VpcScanner() {
  // TODO: getScanners name from tags
  super(
      vpc ->
          ARN_PREFIX_EC2
              + AwsScanner.ARN_SEPARATOR
              + ARN_RESOURCE_TYPE_VPC
              + AwsScanner.RESOURCE_TYPE_SEPARATOR
              + vpc.vpcId(),
      Vpc::vpcId);
}
 
Example #4
Source File: AwsEc2VpcScanner.java    From clouditor with Apache License 2.0 5 votes vote down vote up
@Override
protected Asset transform(Vpc vpc) throws ScanException {
  var asset = super.transform(vpc);

  enrichList(
      asset,
      "staleSecurityGroups",
      this.api::describeStaleSecurityGroups,
      DescribeStaleSecurityGroupsResponse::staleSecurityGroupSet,
      DescribeStaleSecurityGroupsRequest.builder().vpcId(vpc.vpcId()).build());

  return asset;
}
 
Example #5
Source File: ServiceIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private String getVpcId() {
    List<Vpc> vpcs = ec2Client.describeVpcs(DescribeVpcsRequest.builder().build()).vpcs();
    if (vpcs.isEmpty()) {
        Assert.fail("No VPC found in this account.");
    }
    return vpcs.get(0).vpcId();
}
 
Example #6
Source File: AwsEc2VpcScanner.java    From clouditor with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Vpc> list() {
  return this.api.describeVpcs().vpcs();
}