Mahdi
Mahdi

Reputation: 817

Adding modules to a google cloud function

I am follwing documentation to write a simple trigger for my bucket insertion , I am doing this in Python and then deployed the function using gcloud,

my python function is the same as documentation, but I wonder how If i wanna use this function within a project for example I need this function to read the file and publish them to kafka, can I add any external module to this function or using other classes in the python project containing my function?

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']))

Upvotes: 1

Views: 2108

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317750

Yes, the documentation is clear about how to include dependencies.

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.

Upvotes: 3

Related Questions