LoginSignup
6
12

More than 1 year has passed since last update.

Google Cloud Functions の使い方

Last updated at Posted at 2018-03-10

次のページを参考にしました。
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 の引数を受け取る

参考ページ

gcloud functions deploy

6
12
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
6
12