Lambda layers provide a convenient way to package libraries and other dependencies that you can use with your Lambda functions. Using layers reduces the size of uploaded deployment archives and makes it faster to deploy your code. Thit sheet will help you to create a layer for one single library.
follow the instructions on: Install_Python_on_linux2_ec2
On my Cloud9 machine I created a folder: layers and in that folder I should create the folder for the package what I will build the layer for.
mkdir layers
cd layers
mkdir package_name
cd package_name
Create a python folder by running the following command, but do not CD into it!
mkdir python
touch requirements.txt
Install the libraties fromrequirements.txt
into the python folder by running the following command:
python3.9 -m pip install -r requirements.txt --target python/
Zip the contents of the python folder into a layer.zip file by running the following command:
zip -r layer.zip python
Publish the Lambda layer by running the following command:
Important: Replace us-east-1 with the AWS Region that your Lambda function is in.
aws lambda publish-layer-version --layer-name pandas-layer --zip-file fileb://layer.zip --compatible-runtimes python3.9 --region us-east-1
Add the layer to your Lambda function.