This recipe demonstrates how to load a file from Cloud Storage.
View the source code.
-
Follow the Cloud Functions quickstart guide to setup Cloud Functions for your project.
-
Clone this repository:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git cd nodejs-docs-samples/functions/gcs -
Create a Cloud Storage Bucket to stage our deployment:
gsutil mb gs://YOUR_BUCKET_NAME- Replace
YOUR_BUCKET_NAMEwith the name of your Cloud Storage Bucket.
- Replace
-
Upload the sample file to the bucket:
gsutil cp sample.txt gs://YOUR_BUCKET_NAME- Replace
YOUR_BUCKET_NAMEwith the name of your Cloud Storage Bucket.
- Replace
-
Deploy the "wordCount" function with an HTTP trigger:
gcloud alpha functions deploy wordCount --stage-bucket YOUR_BUCKET_NAME --trigger-http- Replace
YOUR_BUCKET_NAMEwith the name of your Cloud Storage Bucket.
- Replace
-
Call the "wordCount" function using the sample file:
gcloud alpha functions call wordCount --data '{"bucket":"YOUR_BUCKET_NAME","file":"sample.txt"}'- Replace
YOUR_BUCKET_NAMEwith the name of your Cloud Storage Bucket.
You should see something like this in your console
The file sample.txt has 114 words - Replace