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.

(ec2): __jsii_type__ error when calling aws_ec2.Vpc.from_lookup() in Python

See original GitHub issue

I 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


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rix0rrrcommented, Feb 8, 2021

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 using Vpc.from_lookup()? It should look somewhat like this:

  "vpc-provider:account=993655754359:filter.isDefault=true:region=us-east-2:returnAsymmetricSubnets=true": {
    "vpcId": "vpc-4407e42d",
    "vpcCidrBlock": "172.31.0.0/16",
    "availabilityZones": [],
    "subnetGroups": [
      ....
}
0reactions
github-actions[bot]commented, Feb 8, 2021

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ec2.Vpc.fromLookup() - AWS Documentation - Amazon.com
No information is available for this page.
Read more >
How to resolve “All arguments to Vpc.fromLookup() must be ...
fromLookup() must be concrete (no Tokens)” during synthesis. This is due to, at this point, calling `Vpc.fromLookup()` will lead to a lookup ...
Read more >
Import Existing VPCs and Subnets into a CDK Python Project
Use Cloudformation exported values from the stacks that created the resources, using cdk.Fn.import_value(); AWS CLI calls, eg aws ec2 describe- ...
Read more >
How to import existing VPC in aws cdk? - Stack Overflow
fromLookup(). The CDK CLI will search for the specified VPC in the the stack's region and account, and import the subnet configuration. Looking ......
Read more >
awslabs/aws-cdk - Gitter
Question: How can I remove the dummy vpc from the stack given the VPC.fromLookup() call did not find the correct vpc? What am...
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