Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. from pyramid.config import Configurator
  2. from configparser import ConfigParser # This will be different in Python 2.7
  3. from functools import partial
  4. import os
  5.  
  6.  
  7. def main(global_config, **settings):
  8. """ This function returns a Pyramid WSGI application.
  9. """
  10. config = Configurator(settings=settings)
  11. config.include('pyramid_jinja2')
  12. config.include('.models')
  13. config.include('.routes')
  14. config.scan()
  15. return config.make_wsgi_app()
  16.  
  17.  
  18. def zappa(config_uri, event, context, **vars):
  19. """
  20. Uses the settings in the configuration uri to bootstrap a wsgi application
  21. through pyramid.
  22.  
  23. Zappa then uses that wsgi application
  24. to create a handler function for use with aws lambda.
  25.  
  26. Event and context information are passed to the handler function which uses
  27. our wsgi application to return a response.
  28.  
  29. :param config_uri: string pointing to paste deploy config file
  30. :param event: aws event
  31. :param context: aws context
  32. :param vars: parameters that will be passed to the configuration file
  33. :return: response
  34. """
  35. config = ConfigParser()
  36. config.read(config_uri)
  37. settings = dict(config.items('app:main', vars=vars))
  38. wsgi_app = main(None, **settings)
  39.  
  40. return wsgi_app(event, context)
  41.  
  42.  
  43. zappa_dev = partial(zappa,
  44. 'development.ini',
  45. dbusername=os.environ.get('dbusername'),
  46. dbpassword=os.environ.get('dbpassword')
  47. )
  48.  
  49. zappa_prod = partial(zappa,
  50. 'production.ini',
  51. dbusername=os.environ.get('dbusername'),
  52. dbpassword=os.environ.get('dbpassword')
  53. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement