Search⌘ K
AI Features

Deploying Google Cloud Functions (GCF)

Explore deploying Google Cloud Functions (GCF) using the Serverless Framework. Understand how to set up environment details, manage Node.js dependencies, deploy functions, and verify public accessibility. Learn how to configure IAM policies to control function access.

We'll cover the following...

Deploying functions

We’ll need to change a few entries in the serverless.yml file. Specifically, we’ll set the region, the project, and the location of the credentials file. As we’ve seen in previous sections, we’ll use sed magic to replace those values.

Shell
cat serverless.yml \
| sed -e "s@us-central1@$GCP_REGION@g" \
| sed -e "s@my-project@$PROJECT_ID@g" \
| sed -e "s@~/.gcloud/keyfile.json@$PATH_TO_ACCOUNT_JSON@g" \
| tee serverless.yml

We’re almost ready to deploy our function, but before we do that, we need to install the dependencies. For that, we’ll need npm, which, more often than not, is installed through Node.js.

Note: If you don’t already have npm, please execute that command.

apt update && \
apt install nodejs npm

Now we can install the dependencies.

Shell
npm install

The output, limited to the relevant information, is as follows.

Shell
...
added 48 packages from 43 contributors and audited 48 packages in 4.145s
...

The processes added 48 dependencies, and we can proceed to deploy the function. ...