引数のない場合の使い方はこちらです。
Google Cloud Functions の使い方
フォルダー構造
$ 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.good_evening = (req, res) => {
var str_out = ""
str_out += "これはテストです。\n"
str_out += "Good Evening\n"
str_out += "今晩は\n"
str_out += "Mar/11/2018 PM 17:35\n"
const user = req.query['user']
const password = req.query['password']
str_out += "user = " + user + "\n"
str_out += "password = " + password + "\n"
res.send(str_out)
}
package.json
{
"name": "sample-http",
"version": "0.0.1"
}
デプロイ
gcloud functions deploy function-apr06 \
--entry-point=good_evening \
--trigger-http \
--runtime=nodejs16 \
--region asia-northeast1
Curl でテスト
curl_get.sh
HOST="https://asia-northeast1-project-apr06.cloudfunctions.net/function-apr06"
curl $HOST/good_evening?user="jiro"\&password="123456" \
-H "Authorization: bearer $(gcloud auth print-identity-token)"
実行結果
$ ./curl_get.sh
これはテストです。
Good Evening
今晩は
Mar/11/2018 PM 17:35
user = jiro
password = 123456