超簡単PythonでGoogle Cloud Functions入門(Hello World)
超簡単にGoogle Cloud Functionsでhello World(Python利用)
最新版はこちらをどうぞ
1. ツールインストール(Linux・Mac)
windowsの場合はこちら参照
$ curl https://sdk.cloud.google.com | bash
$ exec -l $SHELL # シェル再起動
$ gcloud init # 初期化
2. プロジェクト作成
$ gcloud projects create [YOUR_PROJECT_ID] --set-as-default
3. Cloud Functions API 有効化
$ gcloud services enable cloudfunctions.googleapis.com
4. ファイル作成
main.py
def hello_world(request):
return "Hello World!"
5. Cloud Functionsデプロイ
$ gcloud functions deploy hello_world --runtime python37 --trigger-http --region asia-northeast1 --set-env-vars FOO=bar,BAZ=boo
デプロイ成功時に返されるurlにアクセス
以上、超簡単!
6. Cloud Functions削除
$ gcloud functions delete hello_world
7. トラブルシューティング
デプロイ成功時に返されるurlにアクセスできない場合は、デプロイ時の下記の問いにy
Allow unauthenticated invocations of new function [hello_world]?
(y/N)?
8. 参考
この記事が気に入ったらサポートをしてみませんか?