Slide 1

Slide 1 text

Cloud Functions Masaki Iino

Slide 2

Slide 2 text

Cloud Functions Cloud Functions β版 βリリース時にFirebaseもサポートされた ぼちぼち、GAになるらしい

Slide 3

Slide 3 text

Cloud Functions ● サーバレス ● イベント駆動 ● ステートレス ● Node.js

Slide 4

Slide 4 text

料金体系

Slide 5

Slide 5 text

関数の種類 ● HTTP Functions ○ HTTPSリクエストがトリガー ○ 同期実行 ● Background Functions ○ Cloud Pub/Sub ○ Cloud Storage ○ 非同期実行

Slide 6

Slide 6 text

HTTP Functions Hello World するならこう 内部的にExpressを使用している exports.helloWorld = function helloWorld (req, res) { res.send('Hello World!'); };

Slide 7

Slide 7 text

HTTP Functions デプロイ方法 アップロードするバケットとトリガーを指定 バケットは先に作っておく必要あり $ gcloud beta functions deploy helloWorld \ --stage-bucket functions-helloWorld \ --trigger-http

Slide 8

Slide 8 text

Background Functions Hello World するならこう 最後にcallbackを呼ぶ exports.helloWorld = function helloWorld (event, callback) { callback(); };

Slide 9

Slide 9 text

Background Functions デプロイ方法 アップロードするバケットとトリガーを指定 $ gcloud beta functions deploy helloWorld \ --stage-bucket functions-helloWorld \ --trigger-bucket my-bucket $ gcloud beta functions deploy helloWorld \ --stage-bucket functions-helloWorld \ --trigger-topic my-topic

Slide 10

Slide 10 text

パッケージ package.jsonを記述すれば、クラウド上でnpm installされる。 "dependencies": { "request": "^2.81.0" }, const request = require('request'); exports.helloWorld = function helloWorld (req, res) { request('http://www.google.com', (error, response, body) => { res.send('Hello World!'); } };

Slide 11

Slide 11 text

ログ Stackdriver Loggingに出力される(console.logを使う)

Slide 12

Slide 12 text

モニタリング 呼び出し回数 / 実行時間 / メモリ使用量

Slide 13

Slide 13 text

開発環境 公式のエミュレータがあります。(まだalpha

Slide 14

Slide 14 text

デモ