Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@kohei1218

Google Cloud Functions Emulatorの備忘録

More than 1 year has passed since last update.

最近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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kohei1218
主にiOS、たまにAndroid、Rails、ごくまれにLaravel
uzabase
企業活動の意思決定を支える情報インフラの提供

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?