AWS Lambda Serverless and Zappa

263 views
Skip to first unread message

appj...@gmail.com

unread,
Sep 8, 2018, 3:30:28 AM9/8/18
to web...@googlegroups.com
I am trying to migrate my Web2Py app from Heroku to AWS Lambda, using Zappa.  I can get it to start running, but I'm running into errors because web2py is trying to write to the filesystem:


[Errno 30] Read-only file system: '/var/task/deposit': OSError

Traceback (most recent call last):
File "/var/task/handler.py", line 574, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 244, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 150, in __init__
import gluon.main
File "/var/task/gluon/main.py", line 64, in <module>
create_missing_folders()
File "C:\web2py\gluon\admin.py", line 460, in create_missing_folders
File "C:\web2py\gluon\admin.py", line 454, in try_mkdir
OSError: [Errno 30] Read-only file system: '/var/task/deposit'.  

So I commented out the following functions from gluon/main.py

create_missing_app_folders()
and
create_missing_folders()


However, now I'm getting stuck with the DB trying to create tables:


[ERROR] 2018-09-08T07:05:35.270Z 905ef1e6-b335-11e8-816d-07b31200db80 Traceback (most recent call last):
File "/var/task/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/var/task/applications/ads/models/db.py", line 72, in <module>
session.connect(request, response, db=db)
File "C:\web2py\gluon\globals.py", line 946, in connect
File "/var/task/gluon/packages/dal/pydal/base.py", line 587, in define_table
table = self.lazy_define_table(tablename, *fields, **args)
File "/var/task/gluon/packages/dal/pydal/base.py", line 621, in lazy_define_table
polymodel=polymodel)
File "/var/task/gluon/packages/dal/pydal/adapters/base.py", line 797, in create_table
return self.migrator.create_table(*args, **kwargs)
File "/var/task/gluon/packages/dal/pydal/migrator.py", line 275, in create_table
query), table)
File "/var/task/gluon/packages/dal/pydal/migrator.py", line 483, in log
logfile = self.file_open(table._loggername, 'ab')
File "/var/task/gluon/packages/dal/pydal/migrator.py", line 491, in file_open
fileobj = portalocker.LockedFile(filename, mode)
File "C:\web2py\gluon\packages\dal\pydal\contrib\portalocker.py", line 185, in __init__
File "C:\web2py\gluon\packages\dal\pydal\contrib\portalocker.py", line 170, in open_file
IOError: [Errno 2] No such file or directory: '/var/task/applications/ads/databases/sql.log'


Is this a never-ending rabbit hole or is there a way to tell web2py that it cannot write to the filesystem.  I tried
global_setttings.web2py_runtime_gae=True

but that causes a bunch of other problems because GAE resources are not present.

I'd love to get this on AWS Lambda because my application can have temporary 1000x spikes in traffic and Serverless lets me handle this without ops and without paying for idle server time in the evenings.

If I can get this working I will post a deployment recipe.

Thanks,
-Mike

Anthony

unread,
Sep 8, 2018, 3:47:55 PM9/8/18
to web2py-users
You can use InDBMigrator (see https://groups.google.com/d/msg/web2py/lZnL4hRloSc/SSEBnIM0CQAJ). Also, rather than edit main.py, you can just ensure all the folders are there to begin with. Finally, make sure to put sessions in cookies or the database.

Anthony

appj...@gmail.com

unread,
Sep 8, 2018, 8:09:10 PM9/8/18
to web...@googlegroups.com
Thank you Anthony!  That got me past the filesystem issues.  I also needed the following in my model file.

from gluon.dal import InDBMigrator

I have a new issue:

In gluon/template.py, parse_template() filename is coming in as unicode rather than string.  

To fix this, I modified gluon/template.py:781 from this:

    if isinstance(filename, str)




to this:

    if isinstance(filename, str) or isinstance(filename, unicode):




Any ideas?  


Message has been deleted

arafay...@gmail.com

unread,
Oct 6, 2018, 2:17:09 PM10/6/18
to web2py-users
Hi there, 
Can you please tell me the procedure of migrating the web2py app in AWS Lamda or provide me a link that you are following ??

appj...@gmail.com

unread,
Nov 23, 2018, 1:56:39 AM11/23/18
to web2py-users
Hey arafay, Sorry for the delay. 

I plan to post a deployment recipe soon.  There are a lot of little gotchas I've had to work through.  I was able to do it successfully with Zappa (https://github.com/Miserlou/Zappa)

I'm working on doing it for another app and should be able to post my steps in the near future.

David Orme

unread,
Mar 22, 2019, 6:29:27 AM3/22/19
to web2py-users
Hi,

Just wanted to ask about that recipe. I'm using web2py to provide some database management pages and then an API to feed data to a front end. The front end developer is looking for speedups and was asking about deploying to now.sh, to take advantage of the CDN that sits in front of it for caching. That seems to be a very similar approach to what you've done - now.sh uses AWS Lambdas under the hood - and the configuration set up of zappa looks similar to now.sh.

It would be good to get some guidance if you've already solved some of the problems!

Cheers,
David

App Jar

unread,
Apr 23, 2019, 3:24:24 AM4/23/19
to web...@googlegroups.com
Hey David, sorry for the delay.  I rarely check this email.  I'd be happy to talk with you about some of this issues I ran into via phone or email.  Let me know, mi...@appjar.biz.


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/50QdbMCHauM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages