0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gcloud で Google Cloud Functions を使う

Last updated at Posted at 2022-04-04

次の Cloud Function を gcloud から使う方法です。

test-function-uchida-apr04
/**
 * Responds to any HTTP request.
 *
 * @param {!express:Request} req HTTP request context.
 * @param {!express:Response} res HTTP response context.
 */
exports.helloWorld = (req, res) => {
  let message = req.query.message || req.body.message || 'Hello World! Apr/04/2022 PM 16:12';
  res.status(200).send(message);
};

Region は asia-northeast1
Project は project-apr0401
とします。

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

環境設定

$HOME/.config/gcloud/configurations/config_default
[core]
account = example@gmail.com
project = project-apr0401

Login

gcloud auth login

実行コマンド

gcloud functions call  --region=asia-northeast1 test-function-uchida-apr04

実行結果

$ gcloud functions call  --region=asia-northeast1 test-function-uchida-apr04

  Hello World! Apr/04/2022 PM 16:12

Curl を使った例

curl -X GET "https://asia-northeast1-project-apr0401.cloudfunctions.net/test-function-uchida-apr04" \
	-H "Authorization: bearer $(gcloud auth print-identity-token)"
echo ""

Httpie を使った例

http "https://asia-northeast1-project-apr0401.cloudfunctions.net/test-function-uchida-apr04" \
	"Authorization: bearer $(gcloud auth print-identity-token)"
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?