3
5

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.

GCP の Cloud Functions で pipenv が使えている

Last updated at Posted at 2018-12-18

概要

パッケージ管理をpipenvに移行していた中で、GCPの Cloud Functions にも適用してみたところ 正常に動作したのでメモ
厳密な調査をしているわけではないので間違っていた場合は指摘していただけるとありがたいです。
(根本的に理解が間違っているかもしれません。すみません。)

本編

前提

pipenvやらgcloudコマンドやらの環境は整っている前提でメモします。
検証のために適当な外部ライブラリ(今回はrequests)を用いたファンクションをデプロイして動作を確認する。

作業

最終的には以下のようなディレクトリ構造を作る。(main.py以外はコマンドで生成される)

pipenv_functions_test/
├── Pipfile
├── Pipfile.lock
└── main.py

main.pyは以下のよう

main.py
import requests

# gcloud beta functions deploy test_function --trigger-http --runtime python37
def test_function(request):
    return requests.get('http://google.com')

# 動作確認用
if __name__ == '__main__':
    print(test_function('a'))

デプロイコマンド

$ pipenv install requests
$ gcloud beta functions deploy test_function --trigger-http --runtime python37

デプロイ完了時に出力されるURLにアクセスしてみると正常に動作していた。
pipenv でも動作していることが確認できた。
パッケージ管理がだいぶ楽になるので助かる!!

補足

pipenv なしの環境でも試してみたが、No module namedエラーだった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?