Is it possible to use / upload own libraries to IBM Cloud Functions? Or is it limited to the preinstalled packages? I plan to use Python as programming language.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can use any docker image to execute your actions, as long as the images are available on Docker Hub. So you can create your own image with your libraries.
So, for example, if you want your own image that adds the python library
yattag
, a library generating HTML from python code.you can write a Dockerfile like this:
and then build and push
Now you have a public image you can use in OpenWhisk/IBM Cloud.
Here is a simple python hello world using yattag:
create and run the action:
You can bundle your own dependencies. See the docs here https://github.com/apache/incubator-openwhisk/blob/master/docs/actions-python.md#packaging-python-actions-with-a-virtual-environment-in-zip-files for creating a virtual environment with your libraries. The docs provide an example installing dependencies via
requirements.txt
.It is possible to use more libraries than the preinstalled ones. There are some tips & tricks in the IBM Cloud Functions docs and the linked blog articles, e.g., here for Python.
For Python you can either use a virtual environment and package that up or use a zip file with the required Python files. The virtual environment might be easier to start with, but you could end up with a lot of unnecessary files. What I prefer is to download the required files and put them into a zip file on my own. Of course, this is only manageable to a certain degree.
I used that method in this IBM Cloud solution tutorial on serverless GitHub traffic statistics. You can find the source code, including the zip file I created for the Python action, in this GitHub repository (see the functions folder).