(ec2): __jsii_type__ error when calling aws_ec2.Vpc.from_lookup() in Python
See original GitHub issueI am attempting to have a decoupled multistack deployment in Python for the CDK and I am running into an issue where it throws an AttributeError: type object 'tuple' has no attribute '__jsii_type__'
when performing cdk synth
. This issue looks very similar to this aws/jsii/issues/483 which appears to be resolved through this issue aws/jsii/issues/537.
However, in the Python aws_ec2.Vpc.from_lookup()
call it appears to resurface. I verified this is isolated to Python as I created a Typescript project and replicated the code shown below and it works fine.
Considering the impact of this, I would be okay if there were a workaround while this gets resolved such as writing one of the stacks in Typescript and formatting the project such that both the Python CDK stacks and Typescript CDK stack are able to be synthesized from the same project.
If the fix seems achievable as a first issue, I’m happy to try and resolve this myself.
Reproduction Steps
- Run
cdk synth
with the following code:
from aws_cdk import (
core,
aws_ec2 as ec2,
)
class TwitterStreamAppStack(core.Stack):
def __init__(
self,
scope: core.Construct,
id: str,
**kwargs,
) -> None:
super().__init__(scope, id, **kwargs)
vpc = ec2.Vpc.from_lookup(
self, "vpc", vpc_id='vpc-06587757a30949b2e',
)
What did you expect to happen?
I expected to be able to import an existing VPC into the CDK application
What actually happened?
The following exception occurs when executing cdk synth
Traceback (most recent call last):
File "app.py", line 30, in <module>
twitter_stream_app = TwitterStreamAppStack(
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 73, in __call__
inst = super().__call__(*args, **kwargs)
File "/Users/blackenyart/gh_projects/data_pipeline_practice/data_pipeline_practice/twitter_stream_app_stack.py", line 38, in __init__
vpc = ec2.Vpc.from_lookup(
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/aws_cdk/aws_ec2/__init__.py", line 38363, in from_lookup
return jsii.sinvoke(cls, "fromLookup", [scope, id, options])
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 126, in wrapped
return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 353, in sinvoke
args=_make_reference_for_native(self, args),
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 141, in _make_reference_for_native
return [_make_reference_for_native(kernel, i) for i in d]
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 141, in <listcomp>
return [_make_reference_for_native(kernel, i) for i in d]
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 154, in _make_reference_for_native
"data": {
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 155, in <dictcomp>
jsii_name: _make_reference_for_native(
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 174, in _make_reference_for_native
kernel.create(d.__class__, d)
File "/Users/blackenyart/gh_projects/data_pipeline_practice/.venv/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 267, in create
fqn=klass.__jsii_type__ or "Object",
AttributeError: type object 'tuple' has no attribute '__jsii_type__'
Subprocess exited with error 1
Environment
- CDK CLI Version : 1.83.0 (build 827c5f4)
- Framework Version: 1.83.0
- Node.js Version: v15.7.0
- OS : macOS Catalina 10.15.7 (19H114)
- Language (Version): Python 3.8.7
Other
- https://github.com/aws/jsii/issues/483
- https://github.com/aws/jsii/issues/537
- https://github.com/aws/aws-cdk/issues/12160
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
I think you are now pasting the contents of
cdk.context.json
in your new solution.Can you paste them from the project that threw the
__jsii_type__
error when you were usingVpc.from_lookup()
? It should look somewhat like this:⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.