LoginSignup
9
7

More than 5 years have passed since last update.

AWS Lambda Python版でgcloudパッケージを利用しようとするとImportError

Last updated at Posted at 2016-03-14

現象

Kinesisから来たデータをBigQueryに登録するLambda関数をPythonで書いてアップロード後、処理を流すと下記のエラーが発生した。

No module named google.protobuf: ImportError
Traceback (most recent call last):
File "/var/task/main.py", line 17, in kinesis_event_bigquery_handler
insert_records(records)
File "/var/task/main.py", line 29, in insert_records
from gcloud import bigquery
File "/var/task/gcloud/bigquery/__init__.py", line 24, in <module>
from gcloud.bigquery.client import Client
File "/var/task/gcloud/bigquery/client.py", line 18, in <module>
from gcloud.client import JSONClient
File "/var/task/gcloud/client.py", line 20, in <module>
from gcloud._helpers import _determine_default_project
File "/var/task/gcloud/_helpers.py", line 26, in <module>
from google.protobuf import timestamp_pb2
ImportError: No module named google.protobuf

解決策

空ファイル__init__.pyをgoogleパッケージに追加する。virtualenvで環境構築している場合はこう:

$ touch lib/python2.7/site-packages/google/__init__.py

lambda-uploaderを利用している場合は、アップロードの際--virtualenvを忘れずに。

$ lambda-uploader --virtualenv=.

参考文献

9
7
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
7