Reputation: 2733
I have a test Cloud Function (CF) to trigger on update to an object in Cloud Storage.
exports.test_cf = (event, callback) => {
console.log("Test CF executed successfully");
callback();
}
Deployed above function using:
gcloud functions deploy --runtime nodejs6 --trigger-resource [BUCKET-NAME] --trigger-event google.storage.object.archive --timeout=540s --verbosity=info
After setting the versioning on the bucket, I copy a file to the bucket using gsutil
as follows:
gsutil cp <file> gs://[BUCKET-NAME]/
Above command triggered CF. Why is that? As per GCP documentation, google.storage.archive
triggers CF only on updates.
Another question: How to update objects in buckets using gsutil
? I see gsutil rewrite
but it is not same as update.
Upvotes: 0
Views: 1971
Reputation: 2805
Above command triggered CF. Why is that?
You enabled bucket versioning and then used the gsutil
command to copy a file in the bucket. This made a live copy of the file available in the bucket and created an archived version of it, for more information you can visit the Object Versioning documentation. You can verify that by running the gsutil ls -a gs://[BUCKET_NAME]
command, for more information you can visit the Using Object Versioning > Listing archived object versions documentation. So using the -trigger-event google.storage.object.archive
as you used, it will trigger the Cloud Function as it is specified in Google Cloud Storage Triggers > Object Archive documentation, "This event is sent when a live version of an object is archived or deleted."
.
Another question: How to update objects in buckets using gsutil?
If you want to update the object's metadata, you can visit the Objects: update documentation link for more information. However, if you want to update the object it self, you can just upload a new version of the object either from Google Cloud Console
or using the gsutil cp ...
command as specified in the cp - Copy files and objects documentation. This will archive the old object with new version reference number and will make the new version of the object live in the bucket.
Upvotes: 2