-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having a Working Pyramid Example #278
Comments
Okay, this seems to work: from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello %(name)s!' % request.matchdict)
def generate_wsgi_app(app, environ):
config = Configurator()
config.add_route('hello', '/hello/{name}')
config.add_view(hello_world, route_name='hello')
wsgi_app = config.make_wsgi_app()
return wsgi_app(app, environ) {
"dev": {
"app_function": "app.generate_wsgi_app",
"s3_bucket": "lmbda"
}
} |
Does this work?
|
Yes, but I think we need to move that pattern into handler.py. Semi-related #153 |
In case others are in need of a recipe, the following is what I came up with. from pyramid.config import Configurator
from configparser import ConfigParser # This will be different in Python 2.7
from functools import partial
import os
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('.models')
config.include('.routes')
config.scan()
return config.make_wsgi_app()
def zappa(config_uri, event, context, **vars):
"""
Uses the settings in the configuration uri to bootstrap a wsgi application
through pyramid.
Zappa then uses that wsgi application
to create a handler function for use with aws lambda.
Event and context information are passed to the handler function which uses
our wsgi application to return a response.
:param config_uri: string pointing to paste deploy config file
:param event: aws event
:param context: aws context
:param vars: parameters that will be passed to the configuration file
:return: response
"""
config = ConfigParser()
config.read(config_uri)
settings = dict(config.items('app:main', vars=vars))
wsgi_app = main(None, **settings)
return wsgi_app(event, context)
# the following functions will have a signature similar to:
# function(event, context)
# which is what zappa seems to like
zappa_dev = partial(zappa,
'development.ini',
dbusername=os.environ.get('dbusername'),
dbpassword=os.environ.get('dbpassword')
)
zappa_prod = partial(zappa,
'production.ini',
dbusername=os.environ.get('dbusername'),
dbpassword=os.environ.get('dbpassword')
) |
Hi Guys, how should the zappa_settings file look when using pyramid? |
@Nico005 Same as with any other application. Your dev configuration, if using the above code in main_module.py at the root of your project, could start with something like this
|
I'm trying something like:
But I'm receiving an strange Configuration Error
(I will edit later with comments to make it work, as soon as I get it running, for the time, any clues?) |
Ah, the clue is the error message. Zappa excludes py when a pyc is
available. Remove your pycs before packaging
…On Thu, Nov 23, 2017 at 8:03 PM, Guto Maia ***@***.***> wrote:
I'm trying something like:
import os
from wsgiref.simple_server import make_server
from paste.deploy import loadapp
here = os.path.abspath(os.path.dirname(__file__))
def get_app(ini_file):
return loadapp('config:%s/production.ini' % here)
app = get_app()
if __name__ == '__main__':
server = make_server('0.0.0.0', 8888, app)
server.serve_forever()
But I'm receiving an strange Configuration Error
ConfigurationError: No source file for module 'pyramid_jinja2' (.py file
must exist, refusing to use orphan .pyc or .pyo file).
(I will edit later with comments to make it work, as soon as I get it
running, for the time, any clues?)
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#278 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIi0yrxNB_3reM_HansIFVVNOOowxN4ks5s5hXigaJpZM4JrcT4>
.
|
…pa#278 (comment) Try manually parsing the settings file oops forgot filename Add config parser fix params
…pa#278 (comment) Try manually parsing the settings file oops forgot filename Add config parser fix params
Somebody mentioned having some trouble with Pyramid and Zappa, but I haven't explored it yet. It should be somewhat straight forward, but I haven't confirmed it yet. My guess is that it'll mean having something like this:
and then
But, I haven't tried this yet. Does this make sense, @bbangert ? Is there a pattern/convention that'd be better?
The text was updated successfully, but these errors were encountered: