5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Cloud FunctionsのPython(Bata)で環境変数を利用する

Last updated at Posted at 2018-08-09

概要

GCPの管理コンソール上で環境変数の登録ができるのはわかったけど、どうやって使うの?って迷ったのでまとめておきます。

手順

> cd 任意のディレクトリ
> touch main.py
> vi main.py
main.py
import os

def hoge(request):
    return f"{os.environ['HOGE']}: {os.environ['FUGE']}"

で、デプロイします。

> gcloud beta functions deploy hoge \
    --trigger-http \
    --runtime=python37 \
    --set-env-vars \
    HOGE=hoge,FUGE=fuge

で、呼び出します。

> gcloud beta functions call hoge

executionId: gs8um8ry6n3s
result: 'hoge: fuge'

はい。

参考

下記ドキュメントに詳しくのってました。

Using Environment Variables
https://cloud.google.com/functions/docs/env-var

Cloud FunctionsでPython利用記事まとめ
https://qiita.com/kai_kou/items/2f65db5305ba280ad81e

5
2
1

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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?