次のページを参考にしました。
Quickstart: Using the gcloud Command-Line Tool
Google Cloud Platform で、
Cloud Functions API を有効にして下さい。
サンプルのプログラム
フォルダー構造
$ tree
.
├── index.js
└── package.json
index.js
/**
* HTTP Cloud Function.
*
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.hello = (req, res) => {
var str_out = ""
str_out += "これはテストです。\n"
str_out += "Hello World!\n"
str_out += "Good Evening\n"
str_out += "今晩は\n"
str_out += "Mar/10/2018 PM 20:51\n"
res.send(str_out)
}
package.json
{
"name": "sample-http",
"version": "0.0.1"
}
デプロイ
gcloud functions deploy hello \
--entry-point=sum_up \
--trigger-http \
--runtime=nodejs16 \
--region asia-northeast1
関数の一覧
$ gcloud functions list
NAME STATUS TRIGGER REGION
hello ACTIVE HTTP Trigger asia-northeast1
関数のテスト
$ curl https://asia-northeast1-my-project-aug-29-2016.cloudfunctions.net/hello
これはテストです。
Hello World!
Good Evening
今晩は
Mar/10/2018 PM 20:51
関数の URL を調べるには
gcloud functions describe hello --region asia-northeast1
関数の削除
gcloud functions delete hello --region asia-northeast1
引数を Get で受け取るサンプル
Google Cloud Functions で Get の引数を受け取る
引数を Post で受け取るサンプル
Google Cloud Functions で Post の引数を受け取る