Jussi Palo
Jussi Palo

Reputation: 955

AWS Lambda to Firestore error: cannot import name 'cygrpc'

On my AWS Lambda Python 3.6 function I'd like to use Google Firestore (Cloud Firestore BETA) for caching purposes, but as soon as I add

from google.cloud import firestore

to my Python script and upload ZIP to AWS Lambda function, Lambda test come back with error

Unable to import module 'MyLambdaFunction': cannot import name 'cygrpc'. 

AWS CloudWatch log doesn't contain any details on the error, just that same error message.

Lambda function works great on my local dev machine (Windows 10), and I can write to Firestore fine. It also works on AWS if I comment out the import and all Firestore related lines.

Any tips how I could go about solving this?

Upvotes: 4

Views: 3028

Answers (2)

olive_tree
olive_tree

Reputation: 1457

Ran into same issue, i solved it by using the plugin serverless-python-requirements for serverless framework and passing:

pythonRequirements:
    dockerizePip: true

Essentially this installs your c-based packages (and all other packages) in a docker container where it would work and then symlinks them to your lambda fn.

A helpful guide can be found on: https://serverless.com/blog/serverless-python-packaging/

Plugin: https://github.com/UnitedIncome/serverless-python-requirements

Upvotes: 2

Gil Gilbert
Gil Gilbert

Reputation: 7870

The python client for Firestore relies on the C-based implementation of GRPC. This appears not to work by default in AWS Lambda.

Node.js users have reported similar problems and they've documented a workaround of building a docker image.

This should be similar to any getting any other python package that requires native code to work. Perhaps something like this method for getting scikit to work?

I hope this is enough to get you going in the right direction, but unfortunately I don't know anything about AWS Lambda :-(.

Upvotes: 3

Related Questions