Cannot import ready-to-use-Lambda layer
Shyam-Prag opened this issue · 1 comments
I'm unable to use the ready-to-use Lambda Layer.
Steps I followed:
Step 1:
Download repo
Step 2:
cd ready-to-use
Step 3:
Zip the "amazonlinux-2" folder and attach it to my Python3.8 Lambda function
Step 4:
Inside my function, I'm running the below code which simply gets a file from S3 and attempts to use pytesseract.image_to_string:
import json
import os
import boto3
import botocore
import pytesseract
from PIL import Image
def lambda_handler(event, context):
s3 = boto3.resource('s3')
#downloads file from S3 to /tmp directory
BUCKET_NAME = 'xxxxxxx' # replace with your bucket name
KEY = 'test.jpg'
try:
s3.Bucket(BUCKET_NAME).download_file(KEY, '/tmp/my_local_image.jpg')
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print("The object does not exist.")
else:
raise
image = '/tmp/my_local_image.jpg'
text = pytesseract.image_to_string(Image.open(image))
print(text)
return "Hellow world"
Result:
I run into error -> Unable to import module 'lambda_function': No module named 'pytesseract'.
Kindly suggest how to make use of this layer, or could you provide the .zip file to upload as a layer directly.
Hey @Shyam-Prag.
The layer just contains the (language-agnostic) tesseract binaries.
Your error:
Unable to import module 'lambda_function': No module named 'pytesseract'.
suggests, that you need to install the python module pytesseract
as a dependency for your function. Check out the AWS Lambda Documentation on how to do that.
If you prefer to use infrastructure as code, check out the [example
][./example] folder. There are examples (that contain this dependency) ready to deploy using the aws-cdk and the serverless-framework. Cheers.
Check out the releases each release contains a zip file that is ready to go as a layer, containing the language agnostic tesseract bninaries. Be advised that, however pytesseract
is also not included there.