Skip to Content
Google Cloud Platform for Architects
book

Google Cloud Platform for Architects

by Vitthal Srinivasan, Loonycorn Ravi, Judy Raj
June 2018
Intermediate to advanced
372 pages
8h 44m
English
Packt Publishing
Content preview from Google Cloud Platform for Architects

Cloud functions triggered by GCS object notifications

Similarly, Cloud Functions can also be triggered by changes in Cloud Storage buckets:

  1. Write the Cloud Function and save it as index.js:
/** * Background Cloud Function to be triggered by Cloud Storage.. */exports.helloGCS = function (event, callback) { const file = event.data; if (file.resourceState === 'not_exists') { console.log(`File ${file.name} deleted.`); } else if (file.metageneration === '1') { // metageneration attribute is updated on metadata changes. // on create value is 1 console.log(`File ${file.name} uploaded.`); } else 
{ console.log(`File ${file.name} metadata updated.`); } callback();};
  1. Deploy the Cloud Function:
gcloud beta functions deploy helloGCS --trigger-bucket ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Google Cloud Platform Professional Cloud Architect

Google Cloud Platform Professional Cloud Architect

Victor Dantas
Google Cloud Platform for Developers

Google Cloud Platform for Developers

Ted Hunter, Steven Porter

Publisher Resources

ISBN: 9781788834308Other