我正在寻找一种按 Id 过滤子网的方法,从文档看来我们可以使用 SubnetFilter,但我无法将 subnetFilter 解析为 SubnetSelection:
// Err: Initializer type Subnetfilter Is not assignable to variable type SubnetSelection
const subnets = ec2.SubnetSelection = ec2.SubnetFilter.byIds("subnet-id");
const vpc = ec2.Vpc.fromLookup(this, 'vpc', {
vpcName: vpc,
subnets: subnets,
});
我在 GitHub 上研究了这个问题,但不知道如何实现它,也尝试过 ISubnets,但还没有找到可供参考的工作示例,相信我,我已经看过了。抱歉,如果这是一个愚蠢的 Typescript 误解
对现有VPC执行云端查找:
const vpc = ec2.Vpc.fromLookup(this, 'vpc', {
vpcName: 'my-vpc',
});
调用其 selectSubnets 方法,传递
subnetFilters
选项:
const selection: ec2.SubnetSelection = vpc.selectSubnets({
subnetFilters: [ec2.SubnetFilter.byIds(["subnet-id"])],
});