【发布时间】:2020-08-24 13:18:00
【问题描述】:
我正在尝试为 2 个单独帐户中的 2 个 vpc 之间的 vpc 对等创建 cdk 打字稿。相关代码如下。 vpc 创建得很好,但是我无法从 vpc1 和 vpc2 中引用 vpcId 和 peerVpcId。任何人都可以帮忙吗?任何工作示例代码都会非常有帮助。谢谢。
//creation of vpc 1
export class vpc1 extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: EnvProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'vpc1',{
cidr: props.vpcCidr ,
enableDnsHostnames: true,
enableDnsSupport: true,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 24,
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC,
},
{
cidrMask: 24,
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE,
}],
natGateways: 1
}); }}
//creation of vpc 2
export class vpc2 extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: EnvProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'vpc2',{
cidr: props.vpcCidr ,
enableDnsHostnames: true,
enableDnsSupport: true,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 24,
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC,
},
{
cidrMask: 24,
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE,
}],
natGateways: 1
});
}}
export class vpcPeeringfisHiDev extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc_peering = new ec2.CfnVPCPeeringConnection (this, 'vpcPeer',{
vpcId: vpc1.vpc.vpcId, //Error - Property 'vpc' does not exist on type 'typeof vpc1'.ts(2339)
peerVpcId: vpc2.vpc.vpcId //Error - Property 'vpc' does not exist on type 'typeof vpc2'.ts(2339)
}); }}
【问题讨论】:
-
不应该是
vpc1.vpcId而不是vpc1.vpc.vpcId。第二个参考也一样? -
也试过了 - 得到错误 - 类型 'typeof vpc1'.ts(2339) 上不存在属性'vpcId'
标签: typescript amazon-web-services amazon-vpc aws-cdk