How to configure layers for lambda function on python3.9 runtime (Localstack Pro image)

Currently I’m trying to use the matplotlib library in my source code so I want to create a layer. However it is not working now. I don’t know if I’m configuring it wrong, so when I invoke the lambda function, so when I invoke the lambda function the layer doesn’t work?
And also I work on Windows

Below are the commands I use to create layers and lambda functions:

  • pip install -r requirements.txt -t layer → To intall lib and zip it to matplotlib.zip

  • aws --endpoint-url http://localhost:4566 lambda publish-layer-version --layer-name matplotliblayer \ --license-info "MIT" \ --zip-file fileb://layer/matplotlib.zip \ --compatible-runtimes python3.9 \ --compatible-architectures "arm64" "x86_64"

  • aws --endpoint-url=http://localhost:4566 lambda create-function \ --function-name lane-fuction\ --runtime python3.9 \ --role arn:aws:iam::000000000000:role/lambda-role \ --handler route/lane.main \ --zip-file fileb://src/route.zip) \ --timeout 120 \ --layers arn:aws:lambda:ap-northeast-1:000000000000:layer:matplotliblayer:1

The structure of the matplotlib.zip file is as follows:
matplotlib.zip
___└── python
_______└── dependencies

I also tried the structure as shown in the AWS docs

If anyone has successfully installed the layer, please help me. Thank you everyone

Hello @longtran,

It is necessary to include a Linux-compatible version of the Python library in your Lambda layer; otherwise, it will result in the error you have encountered.

You can find more details at Packaging your layer content - AWS Lambda

For Python layers: Working with layers for Python Lambda functions - AWS Lambda

The package details can be found at matplotlib · PyPI

Here is an example of how to get the correct version of the library:

# Download the linux version of python library
pip install matplotlib --platform manylinux2014_x86_64 --only-binary=:all:  --python-version 3.12  --target ./packages/python
# Create a ZIP archive of the Lambda layer
Compress-Archive -Path .\packages\* -DestinationPath layer.zip -Force