Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Cloud Function read from Cloud Storage?

The only docs I can find about using GCF+GCS is https://cloud.google.com/functions/docs/tutorials/storage. AFAICT this is just showing how to use GCS events to trigger GCF.

In the docs for GCF dependencies, it only mentions node modules. Is it possible for GCF code to read from a GCS bucket? Is it simply the case of requiring a node module that knows how to communicate with GCS and if so, are there any examples of that?

like image 735
Rick Viscomi Avatar asked Mar 09 '18 19:03

Rick Viscomi


People also ask

What is the difference between cloud run and cloud function?

Comparing Cloud Function and Cloud Run Cloud Functions only supports a single request at a time for each cloud function instance whereas Cloud Run is able to handle multiple requests at the same time and is able to scale up based on demand.

Which trigger is not supported by cloud functions?

Triggers supported in Cloud Functions (2nd gen) Note: Eventarc does not currently support direct events from Firestore, Google Analytics for Firebase, or Firebase Authentication.

What are cloud functions good for?

Cloud Functions removes the work of managing servers, configuring software, updating frameworks, and patching operating systems. The software and infrastructure are fully managed by Google so that you just add code. Furthermore, provisioning of resources happens automatically in response to events.


1 Answers

Yes you can read and write to storage bucket

const storage = require('@google-cloud/storage')();
const myBucket = storage.bucket('my-bucket');
const file = myBucket.file('my-file');

file.createReadStream().on('data', () => {
    // do something!
});

for more information check the documentations on Google Cloud.

like image 70
Raad Altaie Avatar answered Oct 25 '22 01:10

Raad Altaie