(aws_cdk): AttributeError: module 'aws_cdk' has no attribute 'cx_api'
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
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
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
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.
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)
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, could you please tell me how to solve this problem? Because I'm just doing from aws_cdk import core
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, ...