Google Cloud Functions Emulator - Google Cloud Functions向け開発のお供に
Googleのクラウドサービスでちょっとしたコードを実行するためのサービスがGoogle Cloud Functionsです。AWSで言えばLambda、Azureで言えばAzure Functions相当のサービスになります。 そんなGoogle Cloud FunctionsをローカルでエミュレートできるのがGoogle Cloud Functions Emulatorになります。
Google Cloud Functions Emulatorの使い方
コードを書いたらdeployコマンドでデプロイします。
$ functions deploy helloWorld --trigger-http
Copying file:///var/folders/...1PVvDqx.zip...
Waiting for operation to finish...done.
Deploying function......done.
Function helloWorld deployed.
┌────────────┬──────────────────────────────────────────────────────────────┐
│ Property │ Value │
├────────────┼──────────────────────────────────────────────────────────────┤
│ Name │ helloWorld │
├────────────┼──────────────────────────────────────────────────────────────┤
│ Trigger │ HTTP │
├────────────┼──────────────────────────────────────────────────────────────┤
│ Resource │ http://localhost:8010/nodedemo-1261/us-central1/helloWorld │
├────────────┼──────────────────────────────────────────────────────────────┤
│ Timeout │ 60 seconds │
├────────────┼──────────────────────────────────────────────────────────────┤
│ Local path │ /Users/nakatsugawa/Downloads/chrome_remote_shell/helloWorld │
├────────────┼──────────────────────────────────────────────────────────────┤
│ Archive │ file:///var/folders/...1PVvDqx.zip │
└────────────┴──────────────────────────────────────────────────────────────┘
後はHTTP経由でのアクセスまたはcallを使って実行します。
$ functions call helloWorld
ExecutionId: 3263e7e8-4c33-4d83-8f00-2c1f70ce0a3e
Result: Hello, World!
こんな感じで結果が返ってきます。
Google Cloud Functions Emulatorを使えばGoogle Cloud Functionsにアップロードするための開発をしながらテストが容易にできます。できあがったら実際にデプロイすればいいだけですし、Google Cloud Functions向けの開発を行うなら手元に用意しておきたいツールです。
Google Cloud Functionsはnode/JavaScript製のオープンソース・ソフトウェア(Apache Licnese 2.0)です。