python - 将模块添加到谷歌云功能

标签 python google-cloud-functions

我正在按照文档编写a simple trigger对于我的存储桶插入,我在 Python 中执行此操作,然后使用 gcloud 部署该函数,

我的python函数与文档相同,但我想知道如果我想在项目中使用这个函数,例如我需要这个函数来读取文件并将它们发布到kafka,我可以向这个函数添加任何外部模块吗或者使用包含我的函数的Python项目中的其他类?

def gcs_object_insert(data, context):
    print('Event ID: {}'.format(context.event_id))
    print('Event type: {}'.format(context.event_type))
    print('Bucket: {}'.format(data['bucket']))
    print('File: {}'.format(data['name']))
    print('Metageneration: {}'.format(data['metageneration']))
    print('Created: {}'.format(data['timeCreated']))
    print('Updated: {}'.format(data['updated']))

最佳答案

是的,documentation清楚如何包含依赖项。

A function is allowed to use other third-party libraries as well as other local data. Dependencies in Python are managed with pip and expressed in a metadata file called requirements.txt shipped alongside your function. This file must be in the same directory as the main.py file that contains your function code.

关于python - 将模块添加到谷歌云功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54048808/

相关文章:

Python PySerial 读行超时

python - Pandas groupby 按特定标签获取总行的百分比

android - 在 Firebase Cloud Function 中获取 Android 用户数据

reactjs - Firestore 文档未删除

node.js - 通过 Cloud Function 检索 Firebase 存储图像链接

Firebase 非 Firebase 服务费用

python - 多处理 Queue.get() 挂起

python - 将 try except block 与 python 代码合并

python - 我如何在 Python 中执行 comm Linux 命令

node.js - 使用expressjs时我们如何将文件模块化然后在firebase云函数中使用