Image you are writing an IaaC (Infrastructure as a Code) project with python programming language. There is a good library/sdk that makes it convenient: AWS CDK (Amazon web services cloud development kit). In the same project you can specify lambda source code too.
Now imagine you want that python imports in the lambda function source code would work in the lambda environment and in the project. One of the simplest ways to achieve that is to try/except ImportError like this:
try:
# Lambda-specific import.
from some.path import PathModule
except ImportError:
# Project-specific import.
from iaac.project.source.some.path import PathModule
However, this solution seems to be kinda ugly. Any better suggestions how to write imports that would work in the AWS CDK project and in the Lambda environment?