|
| 1 | +# Google Cloud Function Cloud Storage Event Python example |
| 2 | + |
| 3 | +This folder contains a Google Cloud Function example in Python on Google Cloud Platform (GCP). |
| 4 | + |
| 5 | +It handles a Google Cloud Function that sends information to the function log about an object when it appears in a Cloud Storage bucket. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +* You must have a [Google Cloud Platform (GCP)](http://cloud.google.com/) account. |
| 10 | + |
| 11 | +* The code was written for Python 3 and Google Cloud Python Client Library. |
| 12 | + |
| 13 | +## Using the code |
| 14 | + |
| 15 | +* Access the Google Cloud console. |
| 16 | + |
| 17 | +* Create a Cloud Storage bucket. |
| 18 | + |
| 19 | +* Create a Google Cloud Function: |
| 20 | + * Name: `<CLOUD_FUNCTION_NAME>` |
| 21 | + * Memory allocated: `256 MB` |
| 22 | + * Trigger: `Cloud Storage` |
| 23 | + * Event Type: `Finalise/Create` |
| 24 | + * Bucket: `<BUCKET_NAME>` |
| 25 | + * Source code. You can use 2 options: |
| 26 | + * Inline editor: |
| 27 | + Edit the code of the `main.py` in the browser. |
| 28 | + * ZIP upload: |
| 29 | + Upload a ZIP file containing the `main.py` and `requirements.txt` files. |
| 30 | + * ZIP file: `<ZIP_LOCAL_NAME>` |
| 31 | + * Stage bucket: `<BUCKET_NAME_FOR_STAGGING>` |
| 32 | + * Runtime: `Python 3.7 (Beta)` |
| 33 | + * Function to execute: `gcs_event` |
| 34 | + * Region: `<GOOGLE_CLOUD_REGION>` |
| 35 | + * Timeout: `60 seconds` |
| 36 | + |
| 37 | +* Save the Google Cloud Function. |
| 38 | + |
| 39 | + The function is deployed and run. |
| 40 | + |
| 41 | +* Test the function. |
| 42 | + |
| 43 | + Copy a file in the source Cloud Storage bucket. |
| 44 | + |
| 45 | + You should see the next message in the Google Cloud Function log: |
| 46 | + |
| 47 | + ```bash |
| 48 | + Bucket: <BUCKET_NAME> |
| 49 | + Object: <OBJECT_NAME> |
| 50 | + Object size: <OBJECT_SIZE> |
| 51 | + ``` |
0 commit comments