I am using AWS CDK inside VSCODE. My project layout is such that a single directory contains multiple top-level stacks.
I would like to be able to share code between Stacks. To be specific, it is code and not cross-stack references or resources.
For instance I have a tagging function that I want to be able share and use across all stacks
def default_tag_stacks(*args: cdk.Stack):
for stack in args:
cdk.Tags.of(stack).add("OU", "PlatformInfrastructure")
cdk.Tags.of(stack).add("GovernanceLevel", "Production")
cdk.Tags.of(stack).add("Owner", "Platform")
My editor sees the library and picks up the import, but when running
cdk synth
I get an import error. Is there path variable or another project structure I can follow so I can share code that is not part of a particular stack?
Project structure is as follows
/
lib/tagging.py
stack-1/app.py
stack-2/app.py
Imports are as such
from lib.tagging import tag_all_app_stacks_default
cd stack-1
cdk synth
gives
Traceback (most recent call last):
File "app.py", line 7, in <module>
from lib.tagging import tag_all_app_stacks_default
ModuleNotFoundError: No module named 'lib'