-
Notifications
You must be signed in to change notification settings - Fork 115
Calling functions
Table of Contents
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 beta functions call helloWorld
or
curl https://us-central1-YOUR_PROJECT_ID.cloudfunctions.net/helloWorld
With the Emulator it's very similar:
functions call helloWorld
or
curl http://localhost:8010/YOUR_PROJECT_ID/local/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:
On Linux/Mac:
functions call helloWorld --data='{"message":"Hello, World"}'
On Windows:
functions call helloWorld --data '{\"message\":\"Hello, World\"}'
or
functions call helloWorld --file=/path/to/data.json
If your HTTP function sends a response body then it will be printed to your terminal. If your function logs any data then you can view those logs with:
functions logs read
To call a helloWorld
background function that's been deployed to the production Google Cloud Functions service you might run the following command:
gcloud beta 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:
On Linux/Mac:
functions call helloWorld --data='{"message":"Hello, World"}'
On Windows:
functions call helloWorld --data '{\"message\":\"Hello, World\"}'
or
functions call helloWorld --file=/path/to/data.json
If your background function synchronously returns data, returns a promise that resolves with data, or passes data to the callback, then that data will be printed to your terminal. If your function logs any data then you can view those logs with:
functions logs read
You can manually simulate a Cloud Storage file when you call the function, for example:
On Linux/Mac:
functions call helloWorld --data='{"name":"test.txt","bucket":"my-bucket"}'
On Windows:
functions call helloWorld --data '{\"name\":\"test.txt\",\"bucket\":\"my-bucket\"}'
You can manually simulate a Cloud Pub/Sub message when you call the function, for example:
On Linux/Mac:
functions call helloWorld --data='{"data":"Sm9obg=="}'
On Windows:
functions call helloWorld --data '{\"data\":\"Sm9obg==\"}'
where "Sm9obg=="
is "John"
encoded as a base64
string.
Disclaimer: This is not an official Google product.
@google-cloud/functions-emulator is currently in pre-1.0.0 development. Before the 1.0.0 release, backwards compatible changes and bug fixes will bump the patch version number and breaking changes will bump the minor version number.