Search code examples
amazon-web-servicesamazon-s3amazon-vpcvpcaws-vpc

List the VPCs within a certain AWS Region using Java JDK


I am using the AWS Java JDK and I wish to check if a VPC is within a certain region. The jdk provides an AmazonEC2.describeVpcs() request but it does not provide a means for filtering by region. Does anyone know of a workaround for this?


Solution

  • You should be able to set the region when building the AWS Client, before making the AmazonEC2.describeVpcs() call.

    AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard()
                        .withRegion(Regions.US_WEST_2)
                        .build();
    

    More Info: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html