Skip to content

Commit f76b1af

Browse files
authored
More Cloud Functions (GoogleCloudPlatform#127)
* Make READMEs for all Functions samples consistent. * Add SendGrid Cloud Functions sample. * Switch notes from ol to ul * Add Cloud Functions OCR sample (still needs tests). * Added tests for OCR sample. * Fix lint errors. * Fix test error. * Add missing package.json to sendgrid sample. * Update functions sendgrid sample to use newest sendgrid library. * Fix readme
1 parent a496c56 commit f76b1af

File tree

23 files changed

+1496
-74
lines changed

23 files changed

+1496
-74
lines changed

functions/datastore/README.md

+17-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ View the [source code][code].
1010

1111
## Deploy and Test
1212

13-
1. Follow the [Cloud Functions quickstart guide](https://cloud.google.com/functions/quickstart) to setup Cloud Functions for your project.
13+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
14+
Functions for your project.
1415

1516
1. Clone this repository:
1617

@@ -19,27 +20,35 @@ View the [source code][code].
1920

2021
1. Create a Cloud Storage Bucket to stage our deployment:
2122

22-
gsutil mb gs://<your-bucket-name>
23+
gsutil mb gs://[YOUR_BUCKET_NAME]
24+
25+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
2326

2427
1. Ensure the Cloud Datastore API is enabled:
2528

2629
[Click here to enable the Cloud Datastore API](https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com&redirect=https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/datastore)
2730

2831
1. Deploy the "ds-get" function with an HTTP trigger:
2932

30-
gcloud alpha functions deploy ds-get --bucket <your-bucket-name> --trigger-http --entry-point get
33+
gcloud alpha functions deploy ds-get --bucket [YOUR_BUCKET_NAME] --trigger-http --entry-point get
34+
35+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
3136

3237
1. Deploy the "ds-set" function with an HTTP trigger:
3338

34-
gcloud alpha functions deploy ds-set --bucket <your-bucket-name> --trigger-http --entry-point set
39+
gcloud alpha functions deploy ds-set --bucket [YOUR_BUCKET_NAME] --trigger-http --entry-point set
40+
41+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
3542

3643
1. Deploy the "ds-del" function with an HTTP trigger:
3744

38-
gcloud alpha functions deploy ds-del --bucket <your-bucket-name> --trigger-http --entry-point del
45+
gcloud alpha functions deploy ds-del --bucket [YOUR_BUCKET_NAME] --trigger-http --entry-point del
46+
47+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
3948

4049
1. Call the "ds-set" function to create a new entity:
4150

42-
gcloud alpha functions call ds-set --data '{"kind":"gcf-test","key":"foobar","value":{"message": "Hello World!"}}'
51+
gcloud alpha functions call ds-set --data '{"kind":"gcf-test","key":"foobar","value":{"message":"Hello World!"}}'
4352

4453
1. Call the "ds-get" function to read the newly created entity:
4554

@@ -52,3 +61,5 @@ View the [source code][code].
5261
1. Call the "ds-get" function again to verify it was deleted:
5362

5463
gcloud alpha functions call ds-get --data '{"kind":"gcf-test","key":"foobar"}'
64+
65+
[quickstart]: https://cloud.google.com/functions/quickstart

functions/gcs/README.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ View the [source code][code].
1010

1111
## Deploy and Test
1212

13-
1. Follow the [Cloud Functions quickstart guide](https://cloud.google.com/functions/quickstart) to setup Cloud Functions for your project.
13+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
14+
Functions for your project.
1415

1516
1. Clone this repository:
1617

@@ -19,20 +20,30 @@ View the [source code][code].
1920

2021
1. Create a Cloud Storage Bucket to stage our deployment:
2122

22-
gsutil mb gs://<your-bucket-name>
23+
gsutil mb gs://[YOUR_BUCKET_NAME]
24+
25+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
2326

2427
1. Upload the sample file to the bucket:
2528

26-
gsutil cp sample.txt gs://<your-bucket-name>
29+
gsutil cp sample.txt gs://[YOUR_BUCKET_NAME]
30+
31+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
2732

2833
1. Deploy the "wordCount" function with an HTTP trigger:
2934

30-
gcloud alpha functions deploy wordCount --bucket <your-bucket-name> --trigger-http --entry-point map
35+
gcloud alpha functions deploy wordCount --bucket [YOUR_BUCKET_NAME] --trigger-http --entry-point map
36+
37+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
3138

3239
1. Call the "wordCount" function using the sample file:
3340

34-
gcloud alpha functions call wordCount --data '{"bucket":"<your-bucket-name>","file":"sample.txt"}'
41+
gcloud alpha functions call wordCount --data '{"bucket":"[YOUR_BUCKET_NAME]","file":"sample.txt"}'
42+
43+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
3544

3645
You should see something like this in your console
3746

3847
The file sample.txt has 114 words
48+
49+
[quickstart]: https://cloud.google.com/functions/quickstart

functions/helloworld/README.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,35 @@ View the [documentation][docs] or the [source code][code].
99
[docs]: https://cloud.google.com/functions/writing
1010
[code]: index.js
1111

12-
## Deploy
12+
## Deploy and Test
1313

14-
This example deploys the function with an HTTP trigger.
14+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
15+
Functions for your project.
1516

16-
gcloud alpha functions deploy helloworld --bucket <your-bucket-name> --trigger-http
17+
1. Clone this repository:
1718

18-
## Test
19+
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
20+
cd nodejs-docs-samples/functions/module
1921

20-
gcloud alpha functions call helloworld
22+
1. Create a Cloud Storage Bucket to stage our deployment:
2123

22-
Running the above command should print "Hello World!".
24+
gsutil mb gs://[YOUR_BUCKET_NAME]
2325

24-
You can also use `curl` to trigger the function:
26+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
2527

26-
curl -X POST https://<your-project-region>.<your-project-id>.cloudfunctions.net/helloworld
28+
1. Deploy the `helloworld` function with an HTTP trigger:
29+
30+
gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
31+
32+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
33+
34+
1. Call the `helloworld` function:
35+
36+
gcloud alpha functions call helloworld
37+
38+
You should see something like this in your console:
39+
40+
executionId: abcd1234-0
41+
result: Hello World!
42+
43+
[quickstart]: https://cloud.google.com/functions/quickstart

functions/log/README.md

+31-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,40 @@ View the [documentation][docs] or the [source code][code].
99
[docs]: https://cloud.google.com/functions/walkthroughs
1010
[code]: index.js
1111

12-
## Deploy
12+
## Deploy and Test
1313

14-
This example deploys the function with an HTTP trigger.
14+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
15+
Functions for your project.
1516

16-
gcloud alpha functions deploy helloworld --bucket <your-bucket-name> --trigger-http
17+
1. Clone this repository:
1718

18-
## Test
19+
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
20+
cd nodejs-docs-samples/functions/module
1921

20-
gcloud alpha functions call helloworld
22+
1. Create a Cloud Storage Bucket to stage our deployment:
2123

22-
You can also use `curl` to trigger the function:
24+
gsutil mb gs://[YOUR_BUCKET_NAME]
2325

24-
curl -X POST https://<your-project-region>.<your-project-id>.cloudfunctions.net/helloworld
26+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
27+
28+
1. Deploy the `helloworld` function with an HTTP trigger:
29+
30+
gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
31+
32+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
33+
34+
1. Call the `helloworld` function:
35+
36+
gcloud alpha functions call helloworld
37+
38+
1. Check the logs for the `helloworld` function:
39+
40+
gcloud alpha functions get-logs helloworld
41+
42+
You should see something like this in your console:
43+
44+
D ... User function triggered, starting execution
45+
I ... I am a log entry!
46+
D ... Execution took 1 ms, user function completed successfully
47+
48+
[quickstart]: https://cloud.google.com/functions/quickstart

functions/log2/README.md

+32-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,41 @@ View the [documentation][docs] or the [source code][code].
99
[docs]: https://cloud.google.com/functions/walkthroughs
1010
[code]: index.js
1111

12-
## Deploy
12+
## Deploy and Test
1313

14-
This example deploys the function with an HTTP trigger.
14+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
15+
Functions for your project.
1516

16-
gcloud alpha functions deploy helloworld --bucket <your-bucket-name> --trigger-http
17+
1. Clone this repository:
1718

18-
## Test
19+
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
20+
cd nodejs-docs-samples/functions/module
1921

20-
gcloud alpha functions call helloworld
22+
1. Create a Cloud Storage Bucket to stage our deployment:
2123

22-
You can also use `curl` to trigger the function:
24+
gsutil mb gs://[YOUR_BUCKET_NAME]
25+
26+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
27+
28+
1. Deploy the `helloworld` function with an HTTP trigger:
29+
30+
gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
31+
32+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
33+
34+
1. Call the `helloworld` function:
35+
36+
gcloud alpha functions call helloworld --data '{"message":"Hello World!"}'
37+
38+
1. Check the logs for the `helloworld` function:
39+
40+
gcloud alpha functions get-logs helloworld
41+
42+
You should see something like this in your console:
43+
44+
D ... User function triggered, starting execution
45+
I ... My GCF Function: Hello World!
46+
D ... Execution took 1 ms, user function completed successfully
47+
48+
[quickstart]: https://cloud.google.com/functions/quickstart
2349

24-
curl -X POST https://<your-project-region>.<your-project-id>.cloudfunctions.net/helloworld

functions/message/README.md

+41-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,50 @@ View the [documentation][docs] or the [source code][code].
99
[docs]: https://cloud.google.com/functions/writing
1010
[code]: index.js
1111

12-
## Deploy
12+
## Deploy and Test
1313

14-
This example deploys the function with an HTTP trigger.
14+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
15+
Functions for your project.
1516

16-
gcloud alpha functions deploy helloworld --bucket <your-bucket-name> --trigger-http
17+
1. Clone this repository:
1718

18-
## Test
19+
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
20+
cd nodejs-docs-samples/functions/module
1921

20-
gcloud alpha functions call helloworld
22+
1. Create a Cloud Storage Bucket to stage our deployment:
2123

22-
You can also use `curl` to trigger the function:
24+
gsutil mb gs://[YOUR_BUCKET_NAME]
25+
26+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
27+
28+
1. Deploy the `helloworld` function with an HTTP trigger:
29+
30+
gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
31+
32+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
33+
34+
1. Call the `helloworld` function with some data:
35+
36+
gcloud alpha functions call helloworld --data '{"message":"keyboard cat"}'
37+
38+
1. Call the `helloworld` function without any data:
39+
40+
gcloud alpha functions call helloworld
41+
42+
You should see something like this in your console:
43+
44+
executionId: abcd1234-0
45+
result: Hello World!
46+
47+
1. Check the logs for the `helloworld` function:
48+
49+
gcloud alpha functions get-logs helloworld
50+
51+
You should see something like this in your console:
52+
53+
D ... User function triggered, starting execution
54+
I ... keyboard cat
55+
D ... Execution took 1 ms, user function completed successfully
56+
57+
[quickstart]: https://cloud.google.com/functions/quickstart
2358

24-
curl -X POST https://<your-project-region>.<your-project-id>.cloudfunctions.net/helloworld --data '{"message":"cat"}'

functions/module/README.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,35 @@ View the [documentation][docs] or the [source code][code].
1010
[docs]: https://cloud.google.com/functions/writing
1111
[code]: index.js
1212

13-
## Deploy
13+
## Deploy and Test
1414

15-
This example deploys the function with an HTTP trigger.
15+
1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
16+
Functions for your project.
1617

17-
gcloud alpha functions deploy helloworld --bucket <your-bucket-name> --trigger-http
18+
1. Clone this repository:
1819

19-
## Test
20+
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
21+
cd nodejs-docs-samples/functions/module
2022

21-
gcloud alpha functions call helloworld
23+
1. Create a Cloud Storage Bucket to stage our deployment:
2224

23-
Running the above command should print "Hello World!".
25+
gsutil mb gs://[YOUR_BUCKET_NAME]
2426

25-
You can also use `curl` to trigger the function:
27+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
2628

27-
curl -X POST https://<your-project-region>.<your-project-id>.cloudfunctions.net/helloworld
29+
1. Deploy the `helloworld` function with an HTTP trigger:
30+
31+
gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
32+
33+
* Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
34+
35+
1. Call the `helloworld` function:
36+
37+
gcloud alpha functions call helloworld
38+
39+
You should see something like this in your console:
40+
41+
executionId: abcd1234-0
42+
result: Hello World!
43+
44+
[quickstart]: https://cloud.google.com/functions/quickstart

functions/ocr/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
config.json

0 commit comments

Comments
 (0)