11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Google Cloud Functions で Get の引数を受け取る

Last updated at Posted at 2018-03-11

引数のない場合の使い方はこちらです。
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=nodejs22 \
--region asia-northeast1

関数の一覧

$ gcloud functions list
NAME            STATE   TRIGGER       REGION           ENVIRONMENT
function-apr06  ACTIVE  HTTP Trigger  asia-northeast1  2nd gen

URL の確認

$ gcloud functions describe function-apr06 --region asia-northeast1 | grep url:
url: https://asia-northeast1-project-apr06-2024.cloudfunctions.net/function-apr06

Curl でテスト

curl_get.sh
URL="https://asia-northeast1-project-apr06-2024.cloudfunctions.net/function-apr06"
curl $URL/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

関数の削除

gcloud functions delete function-apr06  --region asia-northeast1
11
7
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
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?