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:
- Created 4 years ago
- Comments:12 (3 by maintainers)
@pagameba is there another way? Hard coding account id does not seem like a good idea.
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.