Open toddysm opened 2 years ago
I'm stuck. I was able to create an API gateway and connect a lambda function to it. I tested this test implementation and was able to get the expected response. So far so good. Next, I went to update the lambda function with the nltk library. This proved to be a little more complicated, since on Lambda you need to include the packages with the function you run. To do that I did the following:
.whl
files and unpackage them. The .whl
files are compiled libraries for specific platforms. lambda_function.py
file, or whatever you called your script to the zip file. This ensures that when it executes it has the necessary libraries in the same directory.I keep getting an error with importing the regex library. I've search and tried every workaround I could find. Any help is appreciated.
Error log message
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'regex._regex'",
"errorType": "Runtime.ImportModuleError",
"requestId": "2bd8bb0d-e6e4-4ec5-9d66-3530024288c8",
"stackTrace": []
}
Time estimate: 10-20hrs Time spent as of 2/22: 10 hrs
Documenting so that I remember what I did, and perhaps to help others.
Deploying a function to AWS Lambda is a little more involved than you may expect, especially if you require non-standard libraries. To ensure that the code that runs locally will work on AWS Lambda, it can be necessary to download the compiled binaries for linux.
Create a new folder for the binaries and navigate to that directory
mkdir packages
cd packages/
Download the nltk binaries
pip download --platform manylinux1_x86_64 --only-binary=:all: --no-binary=:none: nltk
Unzip all the files
unzip '*.whl'
Remove the .whl
files
rm *.whl
To run on AWS Lambda all of the package files and script need to be in a single .zip
file. Build this as follows.
Package all the dependencies.
zip -r ../[archive_name.zip] .
Navigate back to the project root directory and append the function to the archive
cd ..
zip -g [archive_name.zip] [function_name]
Now the [archive_name.zip]
is ready to upload as a Lambda function.
This is related to the following two tasks #46 and #16 We need only the part that determines if the sentence has emotion and determines that emotion. This functionality needs to be exposed via API that we can call.
Time estimates: 8-10 hours