Serverless-offline: Python/non-node support

Created on 25 Aug 2016  路  9Comments  路  Source: dherault/serverless-offline

We're looking to migrate to serverless but our lambdas are currently written in python, which serverless supports but offline doesn't! I thought I saw an issue for this, but can't find now so...

a) are we open to supporting other languages/are there known barriers?
b) Current prototyping approach for offline is to just have a node wrapper that shells out to run whatever other language and pass in event and context... ideally using sockets or FIFO queues, but seems node doesn't support FIFO and I had a little trouble getting a socket to work, so falling back on tmp files for now, since offline/development only performance isn't really a consideration so this is probably fine. Any objections or better ideas for how to do this, or prior art/prior attempts to look at?

enhancement help wanted

Most helpful comment

I fork the project and add support to python via sls invoke local

This don't support any 'print' inside the function and the function do not receive the context
but its good enough to my case and may help someone else.

https://github.com/dsvictor94/serverless-offline

All 9 comments

Hi @bglusman,

Other language support has been a long standing issue for this plugin. Indeed, Node is not optimal to support invoking lambdas written in Python/Java/other. Although we could use child-process or something similar to invoke those non-Node lambdas using Node, with the correct wrapper to handle APIG and Lambda -specific logic, I don't think this is the way to go.
Docker looks like the correct solution, but is cumbersome to implement.

In conclusion, I think that in order to support arbitrary languages, a full refactor of the plugin is necessary. And whatever works is fine, as you said perf is not a priority.

If you are willing to implement a POC (without the APIG and Lambda-specific logic, ie template processing, etc...), I'd be happy to contribute.

Yeah I was thinking perhaps the best way would be to use https://github.com/lambci/docker-lambda but I'm also not very experinced with node so a full refactor may be beyond me. I think I might be able to do a proof of concept via shelling out, but I suspect that's not what you mean. My team's also a little torn between using serverless and something lighter weight and more Python specific like chalice, but chalice has no local development support other than maybe something hacked with flask so not sure where this will leave us, but curious to see where things go and if I can help I will. Thanks David!

I would also be interested in finding out best approach for invoking python with serverless-offline.
My use case is running Ansible (python config management tool) along with my node.js code

+1 for Python offline support. Any update on this?

90% of this plugin is community-driven.
No-one in the core team is working on it (although I might in the following 3 to 6 months).
So only a PR from a user could bring this feature alive.

I fork the project and add support to python via sls invoke local

This don't support any 'print' inside the function and the function do not receive the context
but its good enough to my case and may help someone else.

https://github.com/dsvictor94/serverless-offline

Can we please get python support?

I discovered a trick to workaround this issue. The serverless-offline module handles node.js modules, but sls invoke will handle also modules for python. So just create a node.js module with the same name as the python module, and a method with the same same which calls sls invoke ... and wallah!

Check out the gist to get the gist of it ...

https://gist.github.com/rezen/ea4a958a1ad03404e9c5e4fc5e673abf

Was this page helpful?
0 / 5 - 0 ratings