Support users to upload ZIP package
Cloud Functions supports the function upload mode for user-defined ZIP packages. The principal methods of operation are as follows:
Step1 package the corresponding third-party dependencies, using urllib3 as an example:
pip install -t . urllib3
zip -r code.zip .
Step2 package its own codes: The main.py code looks like the following:
import urllib3
def main(event):
http = urllib3.PoolManager()
result = http.request("GET","http://cloud.mi.com")
return result.data
Add main.py file to code.zip, generated in the previous step
zip code.zip main.py
code.zip generated by the above two steps can be directly uploaded to Cloud Functions. Please note that code.zip cannot exceed 50MB in size. Main entry of your code must be the main (event) in main.py file. Third party package can be placed in directory on the same level with main.py. No changes are needed for other files.