LoginSignup
9
2

More than 5 years have passed since last update.

Cloud Functions で環境変数を使う

Posted at

デプロイ時に --set-env-vars を付ける

この機能はまだ beta なので gcloud beta にする

$ gcloud beta functions NAME --set-env-vars PROJECT=hogehoge KEY=fugafuga

yaml で定義する(オススメ)

.env.yaml
PROJECT: hogehoge
KEY: fugafuga

環境変数を読む

index.js
exports.envVar = (req, res) => {
  // Sends 'bar' as response
  res.send(process.env.PROJECT);
};
main.py
def env_vars(request):
    return os.environ.get('KEY', 'Specified environment variable is not set.')
9
2
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
9
2