Comments (14)
Please, please make this work!
from chalice.
@jamesls Any progress on allowing routes to be in more than just app.py? It'd be super useful for larger projects.
from chalice.
I'm still having issues getting multiple files to work and I'm using the latest chalice which should have this change. Here's my file structure:
project:
- chalicelib:
- __init__.py
- capture.py
- app.py
- __init__.py
In app.py
I try to import capture.py
by adding this line:
from chalicelib import capture
However, I'm still getting the dreaded Unable to import module 'app'
error when I try out the app. I tested this out without using chalice and was able to import/call the module's functions as expected. What am I missing? I'm on chalice 0.5.0
from chalice.
I really liked the idea of chalice, but wanted to use it with a more complex package than I was comfortable wedging all into app.py
. It was a little hacky to get working, but it's a usable workaround. Using a directory structure like so:
mychaliceapp/
mypackage/ #regular python package tree, with tests, dependencies, multiple mods, etc
mypackage/__init__.py
tests/
setup.py
a python setup.py sdist
in my custom package creates a dist/mypackage-0.1.tar.gz
. So in the chalice app, ../mypackage/dist/mypackage-0.1.tar.gz
can be added to requirements.txt
.
To get new code into the lambda deploy is a little tricker since it tries to use the 'replace app.py in the zip file' strategy. So a little refresh_deps.sh
script is helpful:
#!/bin/bash
pushd ../mypackage/ && python setup.py sdist && popd
source .chalice/venv/bin/activate
pip uninstall -y mypackage
rm .chalice/deployments/*.zip
So when changes are made in mypackage
, I just run ./refresh_deps.sh
and it redeploys with them pulled in.
from chalice.
I'm still having issues getting multiple files to work and I'm using the latest chalice which should have this change. Here's my file structure:
Chalice version 1.1.1
project:
- models:
- response_template.py
- init.py
- app.py
In app.py I try to import response_template.py by adding this line:
from models import response_template
However, I'm still getting the dreaded Unable to import module 'app' error when I try out the app. I tested this out without using chalice and was able to import/call the module's functions as expected.
Edit:Got it! directory name should be chalicelib
from chalice.
I like the idea of Chalice. Keep on the good work.
Chalice should follow as closely Flask as possible to enable running the same project in local (Flask mode) for convienient development and debugging. Please keep this in mind and run your projects as Flask apps and see how easy/difficult that is . Alternatively provide a local mode with standard Python debugging in mind. pdb.set_trace() is a good starting point.
When the single app.py limitation will be fixed?
from chalice.
I'm looking forward to this feature.
from chalice.
Awesome feature. Basically you can handle other files by using boto3 with S3 buckets (for the configuration files, for example), but it would be awesome if chalice could handle it (deploy other files in buckets) by itself (despite it would conflict with the intention of being a micro framework).
from chalice.
What about allowing multiple files to be split up into multiple Lambda functions - There is requirements for multiple functions for one API project that this would fulfill
from chalice.
Sorry for the delay on this, I've been bouncing some ideas from #56 and trying out a few prototypes of this feature. I've also been chatting with the rest of the python sdk team on this to get more feedback.
While the find_packages('.')
approach seems to be the most generic solution, I'm finding that it has a few undesirable characteristics:
- It's including things I don't want it to. I generally don't want to include every single python file. Including every python file means that I have no way to control what I'm including in the deployment zip file. I'll typically have:
- python scripts for configuring additional resources (ddb tables, s3 buckets, etc)
- tests code (usually in
tests/
or sometimes justtest_app.py
if it's simple enough.
- It's not including all the things I want. I still need a way to include non python files. Anything from
.json
config files, or misc binary assets.
Now, both of those problems can be solved with an explicit include/exclude list, but I would have to generate those in my common case (where I have tests/, and misc scripts/ files).
The idea that seems to be working out the best is to have a dedicated directory, something like chalicelib/
(not tied to the actual name), that has a simple rule: if the directory exists, anything (recursively) is included in the deployment zipfile.
I have a proof of concept for this, but I'm interested to hear what others think.
from chalice.
PR: #146
from chalice.
#146 is merged. I'll get a release out soon. Please try it out and share any feedback you have.
from chalice.
@d3ming Did you put in chalicelib/init.py the following content :
"from capture import Capture" (assuming Capture is python class)
And why do you have a init.py file in the root directory ?
from chalice.
I am facing similar problem. It would be very helpful if it gets fixed soon.
from chalice.
Related Issues (20)
- Unable to Render HTML Page with Chalice and Jinja2
- Why doesn't {proxy+} work as catchall ? HOT 1
- No way to set retry count on event bridge lambda (cron)?
- Support code signing for AWS Lambda
- AWS Chalice: Error on Redeploying @app.on_dynamodb_record Lambda
- Support for arm64 Graviton HOT 1
- Support for SSE streaming (OpenAI support)
- Config `log_retention_in_days` not working HOT 1
- Aws lambda unzipped size error - aws chalice HOT 3
- Update demo Applications to Python 3.10
- HTTPResponse.create_from_dict raise AttributeError when response body is None
- Support Python 3.12 HOT 2
- Failed to create CDK project in CDK >= 2.73.0
- Why middleware applied at blueprint level applies to whole application ?
- automatic layer config option doesn't work with cdk approach
- Export event classes (or at least BaseLambdaEvent) or provide typeshed stub library
- Update Terraform AWS Provider HOT 4
- CDK integration: Should infrastructure/*.out folders be committed to VCS? HOT 1
- Feature Request: Add SourceAccount on S3 Event
- Project Discontinued? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chalice.