core: unable to import Stack
See original GitHub issueWhat is the problem?
I have a similar problem to issue #17950 with Python. When migrating to cdk 2.0.0/2.1.0
Tried with:
from aws_cdk import Stack
class MyStack(Stack):
Got ImportError: cannot import name 'Stack' from 'aws_cdk' (unknown location)
Also tried with:
import aws_cdk as core
class MyStack(core.Stack):
Got AttributeError: module 'aws_cdk' has no attribute 'Stack'
(using python 3.8.9, cdk 2.1.0)
Reproduction Steps
Add aws-cdk-lib==2.1.0
in requirements.txt
Try to import Stack from core
What did you expect to happen?
The import should work…
What actually happened?
2 different errors with 2 different ways to import the class.
CDK CLI Version
2.1.0
Framework Version
No response
Node.js Version
17.0.1
OS
macOs BigSur M1
Language
Python
Language Version
Python 3.8.9
Other information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
AWS-CDK cannot import core - python
AWS-CDK cannot import core · 1. Does your current directory contain a file called aws_cdk.py ? – jordanm · 6. Sometimes it's the...
Read more >Importing a stack into AWS CloudFormation StackSets
The AWS CloudFormation stack import operation can import existing stacks into new or existing stack sets, so that you can migrate existing stacks...
Read more >How to export and import stack output values in CDK?
To share information between CDK stacks using the low-level CloudFormation features, we need to do following: 1. Import `core` module. The ...
Read more >pulumi stack import
A deployment that was exported from a stack using pulumi stack export and hand-edited to correct inconsistencies due to failed updates, manual changes...
Read more >CDK tips, part 3 – how to unblock cross-stack references
import * as cdk from '@aws-cdk/core'; import * as lambda from ... the effect is the same – the producing Stack fails to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I recreated this issue. It appears that the problem is that you are using aws-cdk.core (or a similar old version) and have not installed aws-cdk-lib. Removing aws-cdk.core with
python3 -m pip uninstall aws-cdk.core
And then installing the new major release withpython -m pip install aws-cdk-lib
should resolve your issue.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.