A Cloud Storage triggered Python Cloud Functions template.
Install dependencies:
pip3 install -r requirements.txt
Run the function:
functions-framework --target=hello_gcs --debug
...
* Running on http://192.168.1.74:8080/ (Press CTRL+C to quit)
...
Inside the scripts folder, run test_local.sh to test the function locally:
./test_local.sh
< HTTP/1.1 200 OK
< Server: Werkzeug/2.2.3 Python/3.10.4
< Date: Fri, 03 Mar 2023 08:12:36 GMT
< Content-Type: text/html; charset=utf-8
You should see the following in the function logs:
Event ID: 123451234512345
Event Type: google.cloud.storage.object.v1.finalized
Bucket: MY_BUCKET
File: MY_FILE.txt
Metageneration: 1
Created: 2020-04-23 07:38:57.230000+00:00
Updated: 2020-04-23 07:38:57.230000+00:00
Run setup.sh to enable required services, grant the
pubsub.publisher
role to the Cloud Storage service account and create a Google
Cloud Storage (GCS) bucket:
./setup.sh
Run deploy.sh to deploy to Google Cloud:
./deploy.sh
Run test_cloud.sh to test the function in Google Cloud:
./test_cloud.sh
When you're done, you can cleanup created resources:
./cleanup.sh