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.

Vpc.from_lookup in v0.36 (python): Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level

See original GitHub issue
  • I’m submitting a …

    • [X ] 🪲 bug report
  • What is the current behavior?

Upgraded to 0.36.0 (build 6d38487). Problems with Vpc.from_lookup()… stack class code at the bottom. Snippet here:

VPCID='vpc-0dc5b6f0c0613263c'
vpc = ec2.Vpc.from_lookup(self, 'vpc', vpc_id=VPCID)

Running cdk synth results in error:

(.env) Admin:~/environment/hmh-dms-poc (master) $ cdk synth jsii.errors.JavaScriptError: Error: Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level at Function.getValue (/tmp/jsii-kernel-GmpUrj/node_modules/@aws-cdk/core/lib/context-provider.js:38:19) at Function.fromLookup (/tmp/jsii-kernel-GmpUrj/node_modules/@aws-cdk/aws-ec2/lib/vpc.js:307:51) at _wrapSandboxCode (/home/ec2-user/environment/hmh-dms-poc/.env/lib/python3.6/dist-packages/jsii/_embedded/jsii/jsii-runtime.js:6514:51) at Kernel._wrapSandboxCode (/home/ec2-user/environment/hmh-dms-poc/.env/lib/python3.6/dist-packages/jsii/_embedded/jsii/jsii-runtime.js:7129:19) at ret._ensureSync (/home/ec2-user/environment/hmh-dms-poc/.env/lib/python3.6/dist-packages/jsii/_embedded/jsii/jsii-runtime.js:6514:25) at Kernel._ensureSync (/home/ec2-user/environment/hmh-dms-poc/.env/lib/python3.6/dist-packages/jsii/_embedded/jsii/jsii-runtime.js:7097:20) at Kernel.sinvoke (/home/ec2-user/environment/hmh-dms-poc/.env/lib/python3.6/dist-packages/jsii/_embedded/jsii/jsii-runtime.js:6513:26)

  • What is the expected behavior (or behavior of feature suggested)?

Expected cdk synth to work with no errors. It worked with earlier cdk releases. Did 0.36 introduce new dependencies for vpc context provider? What does the msg mean:

since account/region are not specified at the stack level

  • Please tell us about your environment:

    • CDK CLI Version: 0.36.0 (build 6d38487)
    • Module Version: 0.36.0
    • OS: [Cloud 9: Amazon Linux AMI release 2018.03]
    • Language: [Python ]

Stack code:

from aws_cdk import core

class HmhDmsPocStack(core.Stack):

    def __init__(self, app: core.App, id: str, **kwargs) -> None:
        super().__init__(app, id)

        # The code that defines your stack goes here
        from aws_cdk import (
            aws_ec2 as ec2
        )
        # Repro error
        VPCID='vpc-0dc5b6f0c0613263c'
        vpc = ec2.Vpc.from_lookup(self, 'vpc', vpc_id=VPCID)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
xelibrioncommented, Jun 27, 2019

@pagameba is there another way? Hard coding account id does not seem like a good idea.

1reaction
pagamebacommented, Jun 27, 2019

to fix this error, you have to add { env: { region: "your-region", account: "your-account-id" } } to the call that creates the new stack instance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot retrieve value from context provider vpc ... - GitHub
Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level #3130.
Read more >
Cannot retrieve value from context provider ami since account ...
If we pick apart the error, it's saying in order to locate the proper AMIs for your EC2 instances, it needs a region/account...
Read more >
awslabs/aws-cdk - Gitter
JSIIError : Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level. Either configure "env" with ...
Read more >
aws-cdk.aws-ec2 - PyPI
If region and account are not specified, the stack could be deployed anywhere and it will have to make a safe choice, limiting...
Read more >
Runtime context - AWS Cloud Development Kit (AWS CDK) v2
The CDK Toolkit uses context to cache values retrieved from your AWS account during synthesis. Values include the Availability Zones in your account...
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