Getting Started Serverless for Cloud Functions

Install serverless

$ npm install -g serverless
$ serverless create --template google-nodejs --path tutorial
Serverless: Generating boilerplate...
Serverless: Generating boilerplate in "/path/to/serverless/tutorial"
_______                             __
|   _   .-----.----.--.--.-----.----|  .-----.-----.-----.
|   |___|  -__|   _|  |  |  -__|   _|  |  -__|__ --|__ --|
|____   |_____|__|  \___/|_____|__| |__|_____|_____|_____|
|   |   |             The Serverless Application Framework
|       |                           serverless.com, v1.25.0
-------'
Serverless: Successfully generated boilerplate for template: "google-nodejs"
$ cd tutorial
$ tree .
.
├── index.js
├── package.json
└── serverless.yml
0 directories, 3 files
$ npm install

Setup credentials

Download credentials, as the guide said

Deployment

Enable deployment manager API https://console.developers.google.com/apis/library/deploymentmanager.googleapis.com/?project=sample-111111

$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling function "first"...
Serverless: Creating deployment...
Serverless: Checking deployment create progress...
.
Serverless: Done...
Serverless: Uploading artifacts...
Serverless: Artifacts successfully uploaded...
Serverless: Updating deployment...
Serverless: Checking deployment update progress...
....
Serverless: Done...
Service Information
service: tutorial
project: sample-111111
stage: dev
region: us-central1
Deployed functions
first
https://us-central1-sample-111111.cloudfunctions.net/http

Execute a function

$ curl https://us-central1-sample-111111.cloudfunctions.net/http
Hello World!
$ serverless invoke --function first
Serverless: zjlo814ayywg Hello World!
$ serverless logs --function first
Serverless: Displaying the 6 most recent log(s):
2018-01-21T12:03:19.907501431Z: Function execution took 7 ms, finished with status code: 200
2018-01-21T12:03:19.901418937Z: Function execution started
2018-01-21T11:59:45.454142179Z: Function execution took 17 ms, finished with status code: 200
2018-01-21T11:59:45.437854329Z: Function execution started
2018-01-21T11:59:06.861655083Z: Function execution took 259 ms, finished with status code: 200
2018-01-21T11:59:06.603478887Z: Function execution started

Like what you read? Give at_ishikawa a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.