Cannot find right method to import existing vpc with ec2.Vpc.fromLookup or ec2.Vpc.fromVpcAttributes
See original GitHub issueIssue: I am trying to import an existing vpc to deploy few lambda, ecs and albs in private subnets. Running into issues when trying to import the vpc using ec2.Vpc.fromLookup or ec2.Vpc.fromVpcAttributes.
The existing vpcid, azs, privatesubnets are exported as dev-vpcId. - value: ‘vpc-xxxxx’ dev-azs - value: ‘us-east-1a,us-east-1b’ dev-privateSubnets - ‘subnet-xxxx,subnet-yyyy’
const vpc = ec2.Vpc.fromVpcAttributes(this,'vpc',{
vpcId: Fn.importValue(envName+'-vpcId'),
availabilityZones: Fn.split(',',Fn.importValue(envName+'-azs')),
privateSubnetIds: Fn.split(',',Fn.importValue(envName+'-privateSubnets')),
})
Error
...../node_modules/@aws-cdk/core/lib/private/resolve.ts:94
throw new Error('Found an encoded list token string in a scalar string context. Use \'Fn.select(0, list)\' (not \'list[0]\') to extract elements from token lists.');
^
Error: Found an encoded list token string in a scalar string context. Use 'Fn.select(0, list)' (not 'list[0]') to extract elements from token lists.
with ec2.Vpc.fromLookup() we cannot use import values
const vpc = ec2.Vpc.fromLookup(this, 'vpc',{
vpcId: Fn.importValue(envName+'-vpcId')
})
Error
..../node_modules/@aws-cdk/aws-ec2/lib/vpc.ts:1040
routerId: natGatewayId,
^
Error: All arguments to Vpc.fromLookup() must be concrete (no Tokens)
Please advise on the right method to import an existing vpc with details from the export values.
This is a 📕 documentation issue
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:27 (15 by maintainers)
Top Results From Across the Web
How to import existing VPC in aws cdk? - Stack Overflow
I am trying to get existing non-default vpc. I tried below options. vpc = ec2.Vpc.from_lookup(self, id = "VPC", vpc_id='vpcid', vpc_name=' ...
Read more >ec2.Vpc.fromLookup() - AWS Documentation - Amazon.com
No information is available for this page.
Read more >Importing VPC IDs into a stack with CDK - DEV Community
When we want to import a VPC ID from another stack using CDK, not all methods will accept the imported value. Errors can...
Read more >awslabs/aws-cdk - Gitter
I looked back a ways but didn't see the answer: is there a roadmap or any projections for ... Import an exported VPC...
Read more >aws-cdk.aws-ec2 - PyPI
Importing an existing VPC. If your VPC is created outside your CDK app, you can use Vpc.fromLookup() . The CDK CLI will search...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fn.importValue
executed during CloudFormation run , butec2.Vpc.fromLookup
runs before CF stack is submitted.I’d try to give up
Fn.importValue
and hardcode map{ dev: 'vpc-xxx', prod: 'vpc-yyyy' }
and use these directly inec2.Vpc.fromLookup
I am using the ec2.Vpc.fromLookup() with tags option to import an existing vpc.
example: