aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(aws_cdk): AttributeError: module 'aws_cdk' has no attribute 'cx_api'

Open chintanghantiwala opened this issue 4 years ago • 6 comments

General Issue

AttributeError: module 'aws_cdk' has no attribute 'cx_api'

The Question

On initiation cdk bootstrap python, started receiving this error. before that able to perform cdk ls, diff and synth.

$ cdk ls Traceback (most recent call last):

File "C:\Program Files\Python39\lib\site-packages\aws_cdk\aws_lambda_python_init_.py", line 213, in from .jsii import * File "C:\Program Files\Python39\lib\site-packages\aws_cdk\aws_lambda_python_jsii_init.py", line 11, in import aws_cdk.aws_ec2.jsii File "C:\Program Files\Python39\lib\site-packages\aws_cdk\aws_ec2_jsii_init.py", line 11, in import aws_cdk.aws_cloudwatch.jsii File "C:\Program Files\Python39\lib\site-packages\aws_cdk\aws_cloudwatch_jsii_init.py", line 11, in import aws_cdk.aws_iam.jsii File "C:\Program Files\Python39\lib\site-packages\aws_cdk\aws_iam_jsii_init.py", line 11, in import aws_cdk.core.jsii File "C:\Program Files\Python39\lib\site-packages\aws_cdk\core_init.py", line 7146, in class ConstructNode(metaclass=jsii.JSIIMeta, jsii_type="@aws-cdk/core.ConstructNode"): File "C:\Program Files\Python39\lib\site-packages\aws_cdk\core_init_.py", line 7197, in ConstructNode runtime_info: typing.Optional[aws_cdk.cx_api.RuntimeInfo] = None, AttributeError: module 'aws_cdk' has no attribute 'cx_api

CDK CLI Version

2.12.0 (build c9786db)

Framework Version

No response

Node.js Version

16.3.0

OS

Windows 10

Language

Python

Language Version

3.9.9

Other information

No response

chintanghantiwala avatar Feb 22 '22 06:02 chintanghantiwala

I would guess that this is happening because you are importing v1 packages. Please see the migration guide on migrating from CDK v1 to v2

peterwoodworth avatar Feb 22 '22 21:02 peterwoodworth

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Feb 25 '22 00:02 github-actions[bot]

I get the same error when I import that library core. It's the import of a core function that returns the error, until then my project worked fine.

File "/home....../.venv/lib/python3.8/site-packages/aws_cdk/core/init.py", line 7205, in ConstructNode runtime_info: typing.Optional[aws_cdk.cx_api.RuntimeInfo] = None, AttributeError: module 'aws_cdk' has no attribute 'cx_api'

I would guess that this is happening because you are importing v1 packages. Please see the migration guide on migrating from CDK v1 to v2

I'm using cdk version 2.5.0 (build 0951122)

LadyCharlotte avatar Apr 26 '22 14:04 LadyCharlotte

Are you importing from aws_cdk import core by any chance? I was also getting this error, because even if you install CDKv2 and use CDKv2 to build it, it still uses v1 if you import incorrect stuff...great.

TomasChmelik avatar Aug 03 '22 05:08 TomasChmelik

@TomasChmelik, could you please tell me how to solve this problem? Because I'm just doing from aws_cdk import core

AChern0v avatar Dec 08 '22 12:12 AChern0v

I think you just shouldn't import aws_cdk.core. Everything from there should now be accessible from just aws_cdk

import aws_cdk as core
# use core.Aws, core.Fn, ...


# or
from aws_cdk import Aws, Fn, ...
# use Aws, Fn, ...

TomasChmelik avatar Jan 02 '23 06:01 TomasChmelik