I have the following Bash script to create and deploy a Lambda layer called 'pythonPackages' that is meant to provide Python libraries to my Lambda functions that are not already installed in the runtime environment.
#!/bin/bash
if [ -d "packages" ]; then
echo "ERROR: Directory 'packages' already exists. Remove it before continuing. Exiting without making chagnes."
exit 1
fi
rm layer_python_packages.zip -f
mkdir packages/python -p
cd packages/python
# pip3 install \
# --platform manylinux2014_aarch64 \
# --target=./lib/python3.12/site-packages \
# --implementation cp \
# --python-version 3.12 \
# --only-binary=:all: --upgrade \
# pandas
pip3 install \
--platform manylinux2014_aarch64 \
--target . \
--python-version 3.12 \
--only-binary=:all: --upgrade \
pandas
rm -rf *.dist-info
cd ../..
zip -r9 layer_python_packages.zip packages
aws lambda publish-layer-version --layer-name pythonPackages --zip-file fileb://layer_python_packages.zip \
--compatible-runtimes python3.12 --compatible-architectures arm64
rm packages -rf
rm layer_python_packages.zip
Then, I have a Lambda function with the line import pandas
. That function prints the following to the CloudWatch logs:
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'pandas'
Traceback (most recent call last):
I do have the latest version of the layer linked to my function:
What am I doing wrong in my script that is making it so that my function can't find the libraries.
I do know that AWS provides a layer that includes Pandas. I will add that temporarily, but need to get this figured out for future use.
Thank you!