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

Using the Emulator with the Cloud SDK

Jason Dobry edited this page Jan 3, 2017 · 7 revisions

Table of Contents

Configuration the SDK to use the Emulator

View your current SDK configuration:

gcloud config list

you'll probably see something like this:

Your active configuration is: [default]

[compute]
region = us-central1
zone = us-central1-c
[core]
account = YOUR_EMAIL@gmail.com
project = YOUR_PROJECT_ID

You probably want your default Cloud SDK configuration to talk the production Google Cloud Functions service, so we'll make a new configuration that will talk to the Emulator:

gcloud config configurations create emulator

In your new configuration, copy over some of the values from your default config:

gcloud config set account YOUR_EMAIL@gmail.com
gcloud config set project YOUR_PROJECT_ID

Now tell the new configuration to talk to the Emulator instead of the production Cloud Functions service. This involves setting api_endpoint_overrides/cloudfunctions to the hostname of the Emulator's REST service:

gcloud config set api_endpoint_overrides/cloudfunctions http://localhost:8008/

You can verify the hostname of the Emulator's REST service with:

functions status

which should print an entry like this:

├────────────────┼───────────────────────────┤
│ REST Service   │ http://localhost:8008/    │
├────────────────┼───────────────────────────┤

You can switch back to your default Cloud SDK configuration at any time:

gcloud config configurations activate default

Listing locally deployed functions

gcloud alpha functions list

Describing a locally deployed function

gcloud alpha functions describe helloWorld

Calling locally deployed functions

gcloud alpha functions call helloWorld --data='{"type":"pizza"}'

Deleting a locally deployed function

gcloud alpha functions delete helloWorld

Cloud SDK commands that don't work with the Emulator

The following Cloud SDK commands don't work with the Emulator:

  • gcloud alpha functions logs read - The Cloud SDK only knows how to read logs in the Cloud, not the local logs.