使用 Java JDK 列出特定 AWS 区域内的 VPC

List the VPCs within a certain AWS Region using Java JDK

我正在使用 AWS Java JDK,我想检查某个 VPC 是否在某个区域内。 jdk 提供了一个 AmazonEC2.describeVpcs() 请求,但它不提供按区域过滤的方法。有人知道解决这个问题的方法吗?

您应该能够在构建 AWS 客户端时设置区域,然后再进行 AmazonEC2.describeVpcs() 调用。

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

更多信息:https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html