- Newest
- Most votes
- Most comments
Hi,
I encountered the same problem with the same error messages, and I was able to fix the issue by following these steps:
-
In the directory where your Python code application is located, create a new directory.
$ mkdir package
-
Run the following command to install the required libraries for your Python code:
$ pip install --target ./package <library_name>
Example: $ pip install --target . /package nltk
-
Invoke the Python interpreter with the following command:
$ python3
import nltk
-
Download the required nltk modules for your application:
Example: nltk.download("punkt") nltk.download("stopwords")
-
Quit the Python interpreter:
quit()
-
Create a directory named "nltk_data" under /package:
$ mkdir nltk_data
-
Copy the nltk data to the directory /package/nltk_data:
$ cp -R /home/user/nltk_data/* ./nltk_data
Note: Replace "/home/user" with your home directory path.
-
Create a .zip file with the installed libraries and nltk_data:
$ cd package $ zip -r ../my_deployment_package.zip . (there is a dot at the end)
-
Add your lambda_function.py (your application) file to the .zip file:
$ cd .. $ zip my_deployment_package.zip lambda_function.py
-
Create an AWS Lambda function on AWS and upload the file "my_deployment_package.zip." Pay attention to the following configuration options:
a) Configuration -> General configuration -> Timeout (choose the needed value to run the application).
b) Configuration -> General configuration -> Memory (choose the needed value to run the application).
c) Configuration -> General configuration -> Ephemeral storage (choose the needed value to run the application).
d) Configuration -> Environment variables -> Key = NLTK_DATA, Value = ./nltk_data
I hope it helps!
Relevant content
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
Alright, I figured it out. I needed to set the nltk.data.path to the new /tmp/nltk_data directory.