我正在按照文档编写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/