Chalice gets confused when used in multiple CDK NestedStack
- Dominant language
- Python
- Stars
- 11.1k
- Forks
- 1k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
I use 2 Chalice API in a same CDK app, each one is handled in a separate nested stack.
```
CDKRootStack
|-ChaliceAPI1
|-ChaliceAPI2
```
First API is correctly generated but the second one has incorrect routes in its API Gateway (it has the routes of the API 1...)
After some investigations the problem is located in chalice.cli.factory.CLIFactory.load_chalice_app() :
`app = importlib.import_module('app')`
the runtime/app.py of the first API is already loaded : calling a second time import_module() doesn't reload it and the wrong 'app.py' file is used for the second template generation.
proposed (working) workaround is to reload the module with importlib.reload() :
```
if "app" in sys.modules:
app = importlib.import_module('app')
importlib.reload(app)
else:
app = importlib.import_module('app')
```
Contributor guide
Research direction
Start at chalice.cli.factory.CLIFactory.load_chalice_app() and inspect how the runtime/app.py module is imported during separate nested-stack generations. Reproduce the two-Chalice nested-stack setup and verify that the second API Gateway receives its own routes rather than the first API's routes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100