Google Cloud | Simple HTTP Endpoint

This example demonstrates how to setup a simple HTTP GET endpoint.

Clone This Example

Step #1 - npm install serverless -g
Step #2 - serverless install -u https://github.com/serverless/examples/tree/master/google-node-simple-http-endpoint -n  google-node-simple-http-endpoint

Pre-request

Follow below link to setup google account for deploying your first serveless application. Google account setup

Simple HTTP example

Setup

  1. Install Serverless with npm install -g serverless
  2. Install the dependencies npm install

Setting the credentials and project

Update the credentials and your project property in the serverless.yml file.

Deployment

serverless deploy

You should see your functions URL endpoint after the deployment

Invoking

curl <the-endpoint-url>

Caveats

Below are the errors will occure during serveless deploy

  1. Enable Cloud Deployment Manager V2 API - make sure Cloud Deployment V2 API is enabled other wise you will get below error during serverless deployment
Error: Cloud Deployment Manager V2 API has not been used in project <projectid> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/deploymentmanager.googleapis.com/overview?project=<projectid> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
  1. Enable Cloud Functions API - make sure Cloud Function API is enabled. Other wise you will get below error.
{"ResourceType":"cloudfunctions.v1beta2.function","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"message":"Cloud Functions API has not been used in project <projectId> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=<projectId> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","status":"PERMISSION_DENIED"
  1. sls deploy --region us-central1 - provide region during sls or serverless deployment , other wise below rest endpoints will be created for your handler , example outof servlerless deployment console.
Service Information
service: node-simple-http-endpoint
project: <project name>
stage: dev
region: undefined
Deployed functions
helloWorld
  https://undefined-<projectname>.cloudfunctions.net/http
view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g