How to import existing VPC in aws cdk?

前端 未结 2 1997
予麋鹿
予麋鹿 2021-01-05 03:54

Hi I am working on aws cdk. I am trying to get existing non-default vpc. I tried below options.

vpc = ec2.Vpc.from_lookup(self, id = \"VPC\", vpc_id=\'vpcid\         


        
2条回答
  •  忘掉有多难
    2021-01-05 04:37

    here is simple example

    //get VPC Info form AWS account, FYI we are not rebuilding we are referencing 
    const DefaultVpc = Vpc.fromVpcAttributes(this, 'vpcdev', {
        vpcId:'vpc-d0e0000b0',
        availabilityZones: core.Fn.getAzs(),
        privateSubnetIds: 'subnet-00a0de00',
        publicSubnetIds: 'subnet-00a0de00'
    });
    
            const yourService = new lambda.Function(this, 'SomeName', {
            code: lambda.Code.fromAsset("lambda"),
            handler: 'handlers.your_handler',
            role: lambdaExecutionRole,
            securityGroup: lambdaSecurityGroup,
            vpc: DefaultVpc,
            runtime: lambda.Runtime.PYTHON_3_7,
            timeout: Duration.minutes(2),
        });
    

提交回复
热议问题