Help us understand the problem. What is going on with this article?

Python Cloud functions をローカル環境で実行する

最近cloud functionsを使っていてローカルでデバッグしたかったので。
自分用覚え書き

pipenv使ってる人はflaskインストールします
環境変数使ってる方はpyyamlも

pipenv install --dev flask, pyyaml

ついでにpipfileにscriptsも追加します

Pipfile
[scripts]
dev = "python main.py"

こんな感じで追加

main.py
if __name__ == "__main__":
    from flask import Flask, request
    import yaml
    app = Flask(__name__)

    # 環境変数読み込み
    with open('.env.yaml', 'r') as f:
        ENV = yaml.load(f)
    MY_TOKEN = ENV.get('MY_TOKEN')

    @app.route('/', methods=['OPTIONS', 'POST', 'GET])
    def index():
        return my_function(request)
    app.run('127.0.0.1', 8000, debug=True)

サーバー起動して簡単に確認できちゃいます

pipenv run dev

deployもこんな感じでbashスクリプト作っておけば簡単

deploy.sh
GCF_NAME="my-func-name"
PROJECT_ID="my-project-id"
GCF_REGION="asia-northeast1"

gcloud functions deploy $GCF_NAME \
  --runtime python37 \
  --region $GCF_REGION \
  --trigger-http \
  --env-vars-file .env.yaml

もっと楽ちんな方法あったら誰か教えてくださ〜い

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away