LoginSignup
2
2

More than 5 years have passed since last update.

Google Cloud Functions Emulatorの備忘録

Last updated at Posted at 2019-02-02

最近Firebaseでcloud functionsを使用することが多く、Cloud Functions Emulatorで試す際に毎回つまってたのでその備忘録

インストール

npm
npm install -g @google-cloud/functions-emulator
yarn
yarn global add @google-cloud/functions-emulator

インストールができればfunctionsコマンドが使用できるようになるのですがzshの方は競合してしまうのでfunctions-emulatorに置き換えてください。

エミュレータの起動
functions start
※起動のエラーで毎回つまる。。

ERROR: Error: Emulator crashed! Check the log file...
    at ChildProcess.child.on (/Users/kohei/.npm-global/lib/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:650:24)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)

こちらパーミッションの問題なのでsudoつけて解決

sudo functions start

関数
index.tsに関数追加

index.ts
exports.hoge = functions.https.onRequest((request, response) => {
     console.log("hogehoge"))
     response.status(200).end()
})

ビルド
npm run build

関数のデプロイ

functions deploy デプロイする関数 --trigger-http

デプロイするとアクセスURLが貼られるのでアクセスして確認

ログ確認
functions logs read

エミュレータの停止
functions stop

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2