我正在写下面这样的代码
export interface MyEc2StackProps extends StackProps {
}
export class MyEc2Stack extends Stack {
public readonly vpc: ec2.Vpc;
constructor(scope: Construct, id: string, props?: MyEc2StackProps) {
const vpc = ec2.Vpc.fromLookup(this, "myvpc", {
isDefault: true,
});
this.vpc = vpc; # this can't be compiled
我想获取 vpc 并导出 vpc 以在其他堆栈中使用。
但是这显示错误,
IVpc has no property from Vpc....
将您的会员类型从
ec2.Vpc
切换到ec2.IVpc
。你需要这样做,因为 ec2.Vpc.fromLookup
返回 ec2.IVpc
。它不是创建一个真正的 VPC,而是查找一个。并非所有操作都可用,因为它不是在您的代码中创建的。但是你应该能够使用 IVpc
来做大多数事情。