Reputation: 13577
I have a Cloud Function that is being triggered by new objects creation in a GCS bucket.
Sometimes things go wrong and the GCF fails. I know that I can enable automatic retry. Still, it would be nice to be able to trigger "object created" event for existing objects during development/debugging. How do I do that?
Upvotes: 4
Views: 1926
Reputation: 1945
Example on how to simulate a file upload event trig:
def hello_gcs(event, context):
"""Triggered by a change to a Cloud Storage bucket.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
print(event)
You have to format the json before use because you have to use "
insteade of '
. Use this site
Json example:
{
"bucket":"<bucket name>",
"contentType":"image/png",
"crc32c":"a1/tEw==",
"etag":"9999999999999999/UCEAE=",
"generation":"9999999999999999",
"id":"<bucket name>/<file name>",
"kind":"storage#object",
"md5Hash":"9999999999999999==",
"mediaLink":"https://www.googleapis.com/download/storage/v1/b/<bucket name>/o/<file name>?generation=9999999999999999&alt=media",
"metageneration":"1",
"name":"Screenshot 2022-02-10 6.09.37 PM.png",
"selfLink":"https://www.googleapis.com/storage/v1/b/<bucket name>/o/<file name>",
"size":"452941",
"storageClass":"STANDARD",
"timeCreated":"2022-02-11T10:22:01.919Z",
"timeStorageClassUpdated":"2022-02-11T10:22:01.919Z",
"updated":"2022-02-11T10:22:01.919Z"
}
Upvotes: 3