Deploying Google Cloud Functions in 5 easy steps


December 04, 2017

Recently I did a project which involved deploying Google Cloud Functions to do the stuff.

This is how to start using GCF the easy way.

First, you need a project to be created already. If not, go to https://console.cloud.google.com and create it. You also need to visit Google Cloud Functions section at least once to make sure GCF API is enabled. You’ll also need to create a storage bucket for a function — there’s no rocket science there, just pick up random name 👍

Second, you need to have Google Cloud SDK installed on your machine. You can download it from here or just go with brew:

brew install google-cloud-sdk

Third, you need to set the current project for Google Cloud SDK. The directory structure doesn’t need to be there yet.

gcloud auth login
gcloud config set project <project_name>

Forth step! We need a nodejs project set up. It’s enough to just do yarn init in a desired project and create index.js with a content of your new cloud function, like this:

exports.fetch = function(req, res) { res.send('Hello, world!'); }

Final step 🎉

gcloud beta functions deploy <your_function_name> --entry-point=<your_entry_point_name_exported_by_index.js> --trigger-http --stage-bucket=<your_stage_bucket>

Example:

gcloud beta functions deploy react-server-side-rendering-service --entry-point=render --trigger-http --stage-bucket=my-awesome-startup-gcf-bucket

That’s it! 😎


me
About the author

Valerii works on Office 365 and is trying to help Microsoft building future-proof products that powers the needs of the industry to make customers productive and happy. He has more than 10 years of experience in building user interfaces and user experience for various companies ranging from small startups to multi-national companies.