question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Explain that Vpc.fromLookup cannot use deploy-time values

See original GitHub issue

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository’s issues are intended for feature requests and bug reports.

  • I’m submitting a …

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior? If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce

class VpcStack(core.Stack):
    def __init__(self, app: core.App, id: str, **kwargs) -> None:
        super().__init__(app, id, **kwargs)
        vpc = aws_ec2.Vpc(scope=self, id='Vpc', cidr=some_cidr))
        core.CfnOutput(
            scope=self,
            id='VpcOutput',
            value=vpc.vpc_id,
            export_name='Vpc'
        )

class OtherStack(core.Stack):
    def __init__(self, app: core.App, id: str, **kwargs) -> None:
        super().__init__(app, id, **kwargs)
        vpc_id = core.Fn.import_value('Vpc')

        aws_s3.Bucket(
            scope=self,
            id='Bucket',
            bucket_name=vpc_id
        )

        vpc = aws_ec2.Vpc.from_lookup(
            scope=self,
            id='Vpc',
            vpc_id=vpc_id
        )

jsii.errors.JSIIError: Invalid context key "vpc-provider:account=***************:filter.vpc-id=${Token[TOKEN.99]}:region=eu-west-1". It contains unresolved tokens

Bucket resolves fine and inherits name from vpc_id. The vpc is not imported though.

  • What is the expected behavior (or behavior of feature suggested)? Vpc.from_lookup imports vpc from the output

  • What is the motivation / use case for changing the behavior or adding this feature? I cannot import existing vpc without hardcoding id

  • Please tell us about your environment:

    • CDK CLI Version: 1.1.0
    • Module Version: 1.1.0
    • OS: [all]
    • Language: [all]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

44reactions
corrjocommented, May 1, 2020

Sorry to be calling attention to an old issue, but what is the recommended way of reusing a vpc without having to hard code the vpc id. It seems like a very common use case, and using name tags for fromLookup works, but also feels fragile since name tags don’t have to be unique.

36reactions
thombergscommented, Oct 4, 2020

@eladb I’ll add my voice to this request. My use case is the following:

  • create a VPC and some other infrastructure in one stack
  • create multiple stacks on top of that stack which put additional resources into the above VPC

I don’t want to manually pass the VPC ID around and hard code it in any scripts to be as flexible as possible.

So, I would very much like to store the VPC ID in the SSM parameter store from the first stack and then retrieve it from the SSM parameter store in other stacks that need the VPC ID.

The storing and retrieval is actually not a problem, but I can’t “hydrate” a VPC from the VPC ID alone, because of the error All arguments to Vpc.fromLookup() must be concrete (no Tokens).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve “All arguments to Vpc.fromLookup() must be ...
fromLookup()` will lead to a lookup when the CDK CLI is executed, therefore, we cannot use any values that will only be available...
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 >
Resources - AWS Cloud Development Kit (AWS CDK) v2
To use Vpc.fromLookup() , the system that synthesizes the stack must have access to the account that owns the Amazon VPC. This is...
Read more >
AWS CDK: is it possible to create EC2 instance or SG into ...
... way to get that is to either create a VPC or to use Vpc.fromLookup() as you pointed out. Neither allow for a...
Read more >
awslabs/aws-cdk - Gitter
We have a sizeable cdk definition for our infrastructure using the Python flavor of aws cdk. ... VPC.fromLookup cant use deploy time values,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found