ImportError when trying to use gcloud package with AWS Lambda Python version

phenomenon

When I wrote a Lambda function that registers data from Kinesis in BigQuery in Python, uploaded it, and then flowed the process, the following error occurred.

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

solution

Add an empty file __init__.py to your google package. If you are building an environment with virtualenv:

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

If you are using lambda-uploader, don't forget --virtualenv when uploading.

$ lambda-uploader --virtualenv=.

References

https://github.com/awslabs/kinesis-deaggregation/blob/master/python/README.md

Recommended Posts

ImportError when trying to use gcloud package with AWS Lambda Python version
[python] A note when trying to use numpy with Cython
Connect to s3 with AWS Lambda Python
Summary of studying Python to use AWS Lambda
I want to AWS Lambda with Python on Mac!
How to use Python lambda
Solution when you want to use cv_bridge with python3 (virtualenv)
[AWS] What to do when you want to pip with Lambda
[AWS] Try adding Python library to Layer with SAM + Lambda (Python)
Python: How to use async with
How to use FTP with Python
Notify HipChat with AWS Lambda (Python)
Use PostgreSQL with Lambda (Python + psycopg2)
[AWS SAM] Introduction to Python version
[Python] Convert CSV file uploaded to S3 to JSON file with AWS Lambda
[September 2020 version] Explains the procedure to use Gmail API with Python
Things to note when running Python on EC2 from AWS Lambda
Prepare an environment to use OpenCV and Pillow with AWS Lambda
[AWS] Using ini files with Lambda [Python]
[Introduction to Python] Let's use foreach with Python
I want to play with aws with python
Trying to handle SQLite3 with Python [Note]
[Road to intermediate Python] Use lambda expressions
Python + Selenium + Headless Chromium with aws lambda
When you want to use it as it is when using it with lambda memo
[AWS] [GCP] I tried to make cloud services easy to use with Python
[Python / Pandas] A bug occurs when trying to replace a DataFrame with `None` with` replace`
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
Upload what you got in request to S3 with AWS Lambda Python
I want to use MATLAB feval with python
[2020 version] How to install Python3 on AWS EC2
Specify the Python executable to use with virtualenv
LINE BOT with Python + AWS Lambda + API Gateway
Serverless application with AWS SAM! (APIGATEWAY + Lambda (Python))
The easiest way to use OpenCV with python
Story of trying to use tensorboard with pytorch
Sample to send slack notification with python lambda
[Improved version] Script to monitor CPU with Python
I want to use Temporary Directory with Python2
How to use tkinter with python in pyenv
Export RDS snapshot to S3 with Lambda (Python)
[AWS / Lambda] How to load Python external library
Upload files to Google Drive with Lambda (Python)
Error when trying to install psycopg2 in Python
Amazon API Gateway and AWS Lambda Python version
Materials to read when getting started with Python
[Python] I want to use only index when looping a list with a for statement
A story that got stuck when trying to upgrade the Python version on GCE
I got stuck when trying to specify a relative path with relative_to () in python
Use AWS Lambda + LINE Notify to notify LINE not to forget your umbrella when you get home
A memo of misunderstanding when trying to load the entire self-made module with Python3
[AWS] Development environment version that tried to build a Python environment with eb [Elastic Beanstalk]
A little trick to know when writing a Twilio application using Python on AWS Lambda
Dynamic HTML pages made with AWS Lambda and Python
Create Python version Lambda function (+ Lambda Layer) with Serverless Framework
How to use python interactive mode with git bash
Check types_map when using mimetypes on AWS Lambda (Python)
[AWS] Make friends with Lambda's JSON input (Python version)
Deploy Python3 function with Serverless Framework on AWS Lambda
Write multiple records to DynamoDB with Lambda (Python, JavaScript)
Create a Layer for AWS Lambda Python with Docker