google-cloud-python: [Speech] does not work from AWS Lambda

Google.cloud.speech image

fails within AWS Lambda environment, works fine on windows

python 3.6

Error message:

Unable to import module 'My_Module': cannot import name 'cygrpc'

To reproduce: create dummy Lambda function, copy code to windows, import google.cloud.speech, install libs into folder, create lambda bundle by zipping together and upload to lambda. module can’t be loaded

  1. Code example
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './gcp-info-insights.json'
import base64 as b64
import boto3
import sys
sys.path.append('./lib')
from google.cloud import speech_v1p1beta1 as speech
from google.cloud.speech_v1p1beta1 import enums
from google.cloud.speech_v1p1beta1 import types

print('Loading function, this will never be reached as some dependencies of google.cloud.api can't be loaded, particularly cygrpc')

s3 = boto3.client('s3')
def lambda_handler(event, context):
 #leave blunk

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

I had the same issue " cannot import name ‘cygrpc’ " while running the lambda.

Solved it with pip install google-cloud-vision in the AMI amzn-ami-hvm-2017.03.1.20170812-x86_64-gp2 instance

and exported the lib/python3.6/site-packages to aws lambda Thank you @tseaver

I had same issue “ImportError: cannot import name ‘cygrpc’ from ‘grpc._cython’”. When import google-cloud-vision.

I build it by docker amazon-linux use ‘pythonRequirements’.

custom:
   pythonRequirements:
     dockerizePip: true

I was able to deploy it from my mac machine using

custom:
  pythonRequirements:
    dockerizePip: true
    useDownloadCache: false
    useStaticCache: false