Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Calling functions

Jason Dobry edited this page Dec 24, 2016 · 9 revisions

Table of Contents

Calling HTTP functions

The Emulator CLI's call commands mirrors that of the Cloud SDK. To call a helloWorld HTTP function that's been deployed to the production Google Cloud Functions service you might run one of the following commands:

gcloud alpha functions call helloWorld

or

curl https://location-YOUR_PROJECT_ID.cloudfunctions.net/helloWorld

With the Emulator it's very similar:

functions call helloWorld

or

curl http://localhost:8010/YOUR_PROJECT_ID/location/helloWorld

To get help on the call command run:

functions call --help

To get the exact Trigger URL of a locally deployed helloWorld HTTP function, you would run the following:

functions describe helloWorld

To pass data to an HTTP function using the call command, use either the --data or --file flags:

functions call helloWorld --data='{"message":"Hello, World"}'

or

functions call helloWorld --file=/path/to/data.json

Calling background functions

To call a helloWorld background function that's been deployed to the production Google Cloud Functions service you might run the following command:

gcloud alpha functions call helloWorld

With the Emulator it's very similar:

functions call helloWorld

To pass data to a background function using the call command, use either the --data or --file flags:

functions call helloWorld --data='{"message":"Hello, World!"}'

or

functions call helloWorld --file=/path/to/data.json

Cloud Storage bucket trigger

You can manually simulate a Cloud Storage file when you call the function, for example:

functions call helloWorld --data='{"name":"test.txt","bucket":"my-bucket"}'

Cloud Pub/Sub topic trigger

You can manually simulate a Cloud Pub/Sub message when you call the function, for example:

functions call helloWorld --data='{"data":"Sm9obg=="}'

where "Sm9obg==" is "John" encoded as a base64 string.

Clone this wiki locally